[gbrainy] More work on mouse support
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gbrainy] More work on mouse support
- Date: Tue, 26 Jan 2010 22:13:03 +0000 (UTC)
commit bb13404822031df68d49f290d2fe6c58bfcc201c
Author: Jordi Mas <jmas softcatala org>
Date: Tue Jan 26 23:13:16 2010 +0100
More work on mouse support
src/Core/Main/Game.cs | 4 +-
src/Core/Makefile.am | 3 +
src/Core/Toolkit/Container.cs | 67 ++++++--------------
src/Core/Toolkit/DrawEventArgs.cs | 44 +++++++++++++
src/Core/Toolkit/DrawableArea.cs | 25 +++++++-
src/Core/Toolkit/HorizontalContainer.cs | 102 +++++++++++++++++++++++++++++++
src/Core/Toolkit/SeletectedEventArgs.cs | 38 +++++++++++
src/Core/Toolkit/Widget.cs | 33 +---------
src/Core/Views/WelcomeView.cs | 24 ++++----
src/Games/Logic/PuzzleCube.cs | 102 +++++++++++++++++++++----------
src/Games/Logic/PuzzlePencil.cs | 20 +++---
src/Games/Logic/PuzzleSquareDots.cs | 34 +++++++---
12 files changed, 347 insertions(+), 149 deletions(-)
---
diff --git a/src/Core/Main/Game.cs b/src/Core/Main/Game.cs
index 5f4b192..383380e 100644
--- a/src/Core/Main/Game.cs
+++ b/src/Core/Main/Game.cs
@@ -274,8 +274,8 @@ namespace gbrainy.Core.Main
OnDrawRequest ();
};
- // If the user has selected an item we should propage an answer
- container.SelectedEvent += delegate (object sender, Widget.SeletectedEventArgs e)
+ // If the user has selected an item we should propagate an answer
+ container.SelectedEvent += delegate (object sender, SeletectedEventArgs e)
{
if (AnswerEvent != null)
AnswerEvent (this, new AnswerEventArgs ((string) e.DataEx));
diff --git a/src/Core/Makefile.am b/src/Core/Makefile.am
index c170e48..18d9d45 100644
--- a/src/Core/Makefile.am
+++ b/src/Core/Makefile.am
@@ -30,6 +30,9 @@ CSFILES = \
Main/IDrawRequest.cs \
Toolkit/Container.cs \
Toolkit/DrawableArea.cs \
+ Toolkit/DrawEventArgs.cs \
+ Toolkit/HorizontalContainer.cs \
+ Toolkit/SeletectedEventArgs.cs \
Toolkit/Widget.cs \
Views/PlayerHistoryView.cs \
Views/ViewsControler.cs \
diff --git a/src/Core/Toolkit/Container.cs b/src/Core/Toolkit/Container.cs
index 3206f90..b4fcd38 100644
--- a/src/Core/Toolkit/Container.cs
+++ b/src/Core/Toolkit/Container.cs
@@ -25,22 +25,25 @@ using gbrainy.Core.Main;
namespace gbrainy.Core.Toolkit
{
- // Horizontal Container
+ //
+ // Base Container class
+ // Does not support rtl and all the coordinates are relative to the child (not the container)
+ //
public class Container : Widget
{
- List <Widget> children;
- bool rtl;
+ protected List <Widget> children = new List <Widget> ();
+ public Container () : base (0, 0)
+ {
+
+ }
+
public Container (double x, double y, double width, double height) : base (width, height)
{
X = x;
Y = y;
- children = new List <Widget> ();
}
- public double X { get; set; }
- public double Y { get; set; }
-
public Widget [] Children {
get { return children.ToArray (); }
}
@@ -58,7 +61,7 @@ namespace gbrainy.Core.Toolkit
OnDrawRequest ();
};
- widget.SelectedEvent += delegate (object sender, Widget.SeletectedEventArgs e)
+ widget.SelectedEvent += delegate (object sender, SeletectedEventArgs e)
{
OnSelected (e);
};
@@ -68,64 +71,32 @@ namespace gbrainy.Core.Toolkit
public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
{
- double x = X, y = Y;
-
- this.rtl = rtl;
-
/*gr.Save ();
gr.Color = new Cairo.Color (0, 0, 1);
gr.Rectangle (X, Y, Width, Height);
gr.Stroke ();
gr.Restore ();*/
- //
- // 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 ();
- }
+ foreach (Widget child in children)
+ {
+ gr.Save ();
+ gr.Translate (child.X, child.Y);
+ child.Draw (gr, area_width, area_height, rtl);
+ gr.Restore ();
}
}
public override void MouseEvent (object obj, MouseEventArgs args)
{
- double x = X, y = Y;
-
- if (rtl == true)
- x += Width;
-
foreach (Widget child in Children)
{
- if (rtl == true)
- x -= child.Width;
-
- if ((args.X >= x) && (args.X < x + child.Width) &&
- (args.Y >= y) && (args.Y < y + child.Height))
+ if ((args.X >= child.X) && (args.X < child.X + child.Width) &&
+ (args.Y >= child.Y) && (args.Y < child.Y + child.Height))
{
child.MouseEvent (this, args);
} else {
child.MouseEvent (this, new MouseEventArgs (-1, -1, args.EventType));
}
-
- if (rtl == false)
- x += child.Width;
}
}
}
diff --git a/src/Core/Toolkit/DrawEventArgs.cs b/src/Core/Toolkit/DrawEventArgs.cs
new file mode 100644
index 0000000..2737e7a
--- /dev/null
+++ b/src/Core/Toolkit/DrawEventArgs.cs
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+
+
+using gbrainy.Core.Libraries;
+
+namespace gbrainy.Core.Toolkit
+{
+ public class DrawEventArgs: EventArgs
+ {
+ public DrawEventArgs (CairoContextEx gr, double width, double height, bool rtl, object data)
+ {
+ Context = gr;
+ Width = width;
+ Height = height;
+ Rtl = rtl;
+ Data = data;
+ }
+
+ public CairoContextEx Context { get; set; }
+ public double Width { get; set; }
+ public double Height { get; set; }
+ public bool Rtl { get; set; }
+ public object Data { get; set; }
+ }
+}
diff --git a/src/Core/Toolkit/DrawableArea.cs b/src/Core/Toolkit/DrawableArea.cs
index 92cf89f..b387f1b 100644
--- a/src/Core/Toolkit/DrawableArea.cs
+++ b/src/Core/Toolkit/DrawableArea.cs
@@ -18,6 +18,7 @@
*/
using System;
+using Cairo;
using gbrainy.Core.Libraries;
using gbrainy.Core.Main;
@@ -30,25 +31,43 @@ namespace gbrainy.Core.Toolkit
public virtual event WidgetSelectedEventHandler SelectedRequestEvent;
bool hoover;
+ public DrawableArea (double x, double y, double width, double height) : base (width, height)
+ {
+ X = x;
+ Y = y;
+ }
+
public DrawableArea (double width, double height) : base (width, height)
{
}
+ public Rectangle SelectedArea { get; set; }
+
public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
{
+ /*gr.Save ();
+ gr.Color = new Cairo.Color (1, 0, 0);
+ gr.Rectangle (0, 0, Width, Height);
+ gr.Stroke ();
+ gr.Restore ();*/
+
if (hoover == true)
{
double lw = gr.LineWidth;
double [] dashes = {0.01, /* ink */
- 0.01, /* skip */
- };
+ 0.01, /* skip */ };
gr.Save ();
gr.Color = new Cairo.Color (0.5, 0.5, 0.5, 1);
gr.SetDash (dashes, 0);
- gr.Rectangle (-lw, -lw, Width + lw * 2, Height + lw * 2);
+
+ 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 ();
}
diff --git a/src/Core/Toolkit/HorizontalContainer.cs b/src/Core/Toolkit/HorizontalContainer.cs
new file mode 100644
index 0000000..a091abd
--- /dev/null
+++ b/src/Core/Toolkit/HorizontalContainer.cs
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2010 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+using System.Collections.Generic;
+
+using gbrainy.Core.Libraries;
+using gbrainy.Core.Main;
+
+namespace gbrainy.Core.Toolkit
+{
+ // Horizontal container (supports RTL)
+ // Child controls are stacked horizontally one each other (does not uses X, Y child coordinates)
+ public class HorizontalContainer : Container
+ {
+ bool rtl;
+
+ public HorizontalContainer (double x, double y, double width, double height) : base (x, y, width, height)
+ {
+
+ }
+
+ public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
+ {
+ double x = X, y = Y;
+
+ this.rtl = rtl;
+
+ /*gr.Save ();
+ gr.Color = new Cairo.Color (0, 0, 1);
+ gr.Rectangle (X, Y, Width, Height);
+ gr.Stroke ();
+ gr.Restore ();*/
+
+ //
+ // 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 MouseEvent (object obj, MouseEventArgs args)
+ {
+ double x = X, y = Y;
+
+ if (rtl == true)
+ x += Width;
+
+ foreach (Widget child in Children)
+ {
+ if (rtl == true)
+ x -= child.Width;
+
+ if ((args.X >= x) && (args.X < x + child.Width) &&
+ (args.Y >= y) && (args.Y < y + child.Height))
+ {
+ child.MouseEvent (this, args);
+ } else {
+ child.MouseEvent (this, new MouseEventArgs (-1, -1, args.EventType));
+ }
+
+ if (rtl == false)
+ x += child.Width;
+ }
+ }
+ }
+}
diff --git a/src/Core/Toolkit/SeletectedEventArgs.cs b/src/Core/Toolkit/SeletectedEventArgs.cs
new file mode 100644
index 0000000..a56e096
--- /dev/null
+++ b/src/Core/Toolkit/SeletectedEventArgs.cs
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Jordi Mas i Hernà ndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+using System;
+
+using gbrainy.Core.Main;
+using gbrainy.Core.Libraries;
+
+namespace gbrainy.Core.Toolkit
+{
+ public class SeletectedEventArgs: EventArgs
+ {
+ public SeletectedEventArgs (object data, object data_ex)
+ {
+ Data = data;
+ DataEx = data_ex;
+ }
+
+ public object Data { get; set; }
+ public object DataEx { get; set; }
+ }
+}
diff --git a/src/Core/Toolkit/Widget.cs b/src/Core/Toolkit/Widget.cs
index 1b3e4f5..c6a4112 100644
--- a/src/Core/Toolkit/Widget.cs
+++ b/src/Core/Toolkit/Widget.cs
@@ -34,47 +34,18 @@ namespace gbrainy.Core.Toolkit
public event WidgetSelectedEventHandler SelectedEvent;
ISynchronizeInvoke synchronize;
- public class DrawEventArgs: EventArgs
- {
- public DrawEventArgs (CairoContextEx gr, double width, double height, bool rtl, object data)
- {
- Context = gr;
- Width = width;
- Height = height;
- Rtl = rtl;
- Data = data;
- }
-
- public CairoContextEx Context { get; set; }
- public double Width { get; set; }
- public double Height { get; set; }
- public bool Rtl { get; set; }
- public object Data { get; set; }
- }
-
- public class SeletectedEventArgs: EventArgs
- {
- public SeletectedEventArgs (object data, object data_ex)
- {
- Data = data;
- DataEx = data_ex;
- }
-
- public object Data { get; set; }
- public object DataEx { get; set; }
- }
-
public Widget (double width, double height)
{
Width = width;
Height = height;
}
- public bool Visible { get; set; }
public bool Sensitive { get; set; }
public object Data { get; set; }
public object DataEx { get; set; }
+ public double X { get; set; }
+ public double Y { get; set; }
public double Width { get; set; }
public double Height { get; set; }
diff --git a/src/Core/Views/WelcomeView.cs b/src/Core/Views/WelcomeView.cs
index a1aa395..381ac8e 100644
--- a/src/Core/Views/WelcomeView.cs
+++ b/src/Core/Views/WelcomeView.cs
@@ -44,19 +44,19 @@ namespace gbrainy.Core.Views
containers = new List <Toolkit.Container> ();
/* Logic */
- container = new Container (0.05, y, 0.95, space);
+ container = new HorizontalContainer (0.05, y, 0.95, space);
containers.Add (container);
drawable_area = new DrawableArea (0.17, image_size);
container.AddChild (drawable_area);
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
e.Context.DrawImageFromAssembly ("logic-games.svg", 0, 0, image_size, image_size);
};
drawable_area = new DrawableArea (0.75, 0.25);
container.AddChild (drawable_area);
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
e.Context.DrawStringWithWrapping (0, 0,
Catalog.GetString ("Logic puzzles. Challenge your reasoning and thinking skills."),
@@ -65,19 +65,19 @@ namespace gbrainy.Core.Views
/* Math */
y += space;
- container = new Container (0.05, y, 0.95, space);
+ container = new HorizontalContainer (0.05, y, 0.95, space);
containers.Add (container);
drawable_area = new DrawableArea (0.17, image_size);
container.AddChild (drawable_area);
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
e.Context.DrawImageFromAssembly ("math-games.svg", 0, 0, image_size, image_size);
};
drawable_area = new DrawableArea (0.75, 0.25);
container.AddChild (drawable_area);
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
e.Context.DrawStringWithWrapping (0, 0,
Catalog.GetString ("Mental calculation. Arithmetical operations that test your mental calculation abilities."),
@@ -86,19 +86,19 @@ namespace gbrainy.Core.Views
/* Memory */
y += space;
- container = new Container (0.05, y, 0.95, space);
+ container = new HorizontalContainer (0.05, y, 0.95, space);
containers.Add (container);
drawable_area = new DrawableArea (0.17, image_size);
container.AddChild (drawable_area);
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
e.Context.DrawImageFromAssembly ("memory-games.svg", 0, 0, image_size, image_size);
};
drawable_area = new DrawableArea (0.75, 0.25);
container.AddChild (drawable_area);
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
e.Context.DrawStringWithWrapping (0, 0,
Catalog.GetString ("Memory trainers. To prove your short term memory."),
@@ -107,19 +107,19 @@ namespace gbrainy.Core.Views
/* Verbal */
y += space;
- container = new Container (0.05, y, 0.95, space);
+ container = new HorizontalContainer (0.05, y, 0.95, space);
containers.Add (container);
drawable_area = new DrawableArea (0.17, image_size);
container.AddChild (drawable_area);
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
e.Context.DrawImageFromAssembly ("verbal-games.svg", 0, 0, image_size, image_size);
};
drawable_area = new DrawableArea (0.75, 0.25);
container.AddChild (drawable_area);
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
e.Context.DrawStringWithWrapping (0, 0,
Catalog.GetString ("Verbal analogies. Challenge your verbal aptitude."),
diff --git a/src/Games/Logic/PuzzleCube.cs b/src/Games/Logic/PuzzleCube.cs
index d5443ab..4a721a7 100755
--- a/src/Games/Logic/PuzzleCube.cs
+++ b/src/Games/Logic/PuzzleCube.cs
@@ -23,6 +23,7 @@ using System;
using gbrainy.Core.Main;
using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
namespace gbrainy.Games.Logic
{
@@ -30,6 +31,9 @@ namespace gbrainy.Games.Logic
{
private char question;
const int pairs = 4;
+ const double figure_size = 0.1;
+ const double txtoff_x = 0.04;
+ const double txtoff_y = 0.03;
private int[] question_answer =
{
@@ -52,46 +56,80 @@ namespace gbrainy.Games.Logic
int pair = random.Next (pairs);
question = (char) (48 + question_answer[pair * 2]);
right_answer += (char) (48 + question_answer[(pair * 2) + 1]);
- }
-
- public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
- {
+
+ Container container;
+ DrawableArea drawable_area;
double x = DrawAreaX + 0.1;
- double y = DrawAreaY + 0.1;
- const double txtoff_x = 0.04;
- const double txtoff_y = 0.03;
+ double y = DrawAreaY + 0.2;
- base.Draw (gr, area_width, area_height, rtl);
+ container = new Container ();
+ AddWidget (container);
- gr.Rectangle (x + 0.1, y, 0.1, 0.1);
- gr.Stroke ();
- gr.MoveTo (x + 0.1 + txtoff_x, y + txtoff_y);
- gr.ShowPangoText ("1");
+ drawable_area = new DrawableArea (x + 0.1, y, figure_size, figure_size);
+ drawable_area.DataEx = "1";
+ container.AddChild (drawable_area);
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+ {
+ e.Context.Rectangle (0, 0, figure_size, figure_size);
+ e.Context.Stroke ();
+ e.Context.MoveTo (txtoff_x, txtoff_y);
+ e.Context.ShowPangoText ("1");
+ };
- gr.Rectangle (x + 0.2, y, 0.1, 0.1);
- gr.Stroke ();
- gr.MoveTo (x + 0.2 + txtoff_x, y + txtoff_y);
- gr.ShowPangoText ("2");
+ drawable_area = new DrawableArea (x + 0.2, y, figure_size, figure_size);
+ drawable_area.DataEx = "2";
+ container.AddChild (drawable_area);
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+ {
+ e.Context.Rectangle (0, 0, figure_size, figure_size);
+ e.Context.Stroke ();
+ e.Context.MoveTo (txtoff_x, txtoff_y);
+ e.Context.ShowPangoText ("2");
+ };
- gr.Rectangle (x + 0.2, y + 0.1, 0.1, 0.1);
- gr.Stroke ();
- gr.MoveTo (x + 0.2 + txtoff_x, y + 0.1 + txtoff_y);
- gr.ShowPangoText ("3");
+ drawable_area = new DrawableArea (x + 0.2, y + 0.1, figure_size, figure_size);
+ drawable_area.DataEx = "3";
+ container.AddChild (drawable_area);
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+ {
+ e.Context.Rectangle (0, 0, figure_size, figure_size);
+ e.Context.Stroke ();
+ e.Context.MoveTo (txtoff_x, txtoff_y);
+ e.Context.ShowPangoText ("3");
+ };
- gr.Rectangle (x + 0.3, y + 0.1, 0.1, 0.1);
- gr.Stroke ();
- gr.MoveTo (x + 0.3 + txtoff_x, y + 0.1 + txtoff_y);
- gr.ShowPangoText ("4");
+ drawable_area = new DrawableArea (x + 0.3, y + 0.1, figure_size, figure_size);
+ drawable_area.DataEx = "4";
+ container.AddChild (drawable_area);
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+ {
+ e.Context.Rectangle (0, 0, figure_size, figure_size);
+ e.Context.Stroke ();
+ e.Context.MoveTo (txtoff_x, txtoff_y);
+ e.Context.ShowPangoText ("4");
+ };
- gr.Rectangle (x + 0.4, y + 0.1, 0.1, 0.1);
- gr.Stroke ();
- gr.MoveTo (x + 0.4 + txtoff_x, y + 0.1 + txtoff_y);
- gr.ShowPangoText ("5");
+ drawable_area = new DrawableArea (x + 0.4, y + 0.1, figure_size, figure_size);
+ drawable_area.DataEx = "5";
+ container.AddChild (drawable_area);
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+ {
+ e.Context.Rectangle (0, 0, figure_size, figure_size);
+ e.Context.Stroke ();
+ e.Context.MoveTo (txtoff_x, txtoff_y);
+ e.Context.ShowPangoText ("5");
+ };
- gr.Rectangle (x + 0.4, y + 0.2, 0.1, 0.1);
- gr.Stroke ();
- gr.MoveTo (x + 0.4 + txtoff_x, y + 0.2 + txtoff_y);
- gr.ShowPangoText ("6");
+ drawable_area = new DrawableArea (x + 0.4, y + 0.2, figure_size, figure_size);
+ drawable_area.DataEx = "6";
+ container.AddChild (drawable_area);
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+ {
+ e.Context.Rectangle (0, 0, figure_size, figure_size);
+ e.Context.Stroke ();
+ e.Context.MoveTo (txtoff_x, txtoff_y);
+ e.Context.ShowPangoText ("6");
+ };
}
}
}
diff --git a/src/Games/Logic/PuzzlePencil.cs b/src/Games/Logic/PuzzlePencil.cs
index 7987723..8ee2bc2 100644
--- a/src/Games/Logic/PuzzlePencil.cs
+++ b/src/Games/Logic/PuzzlePencil.cs
@@ -60,7 +60,7 @@ namespace gbrainy.Games.Logic
}
double x = DrawAreaX, y = DrawAreaY + 0.1, box_size = (1 - (DrawAreaX * 2)) / 3;
- Container container1, container2, container = null;
+ HorizontalContainer container1, container2, container = null;
DrawableArea drawable_area;
for (int figure = 0; figure < figures; figure++)
@@ -68,14 +68,14 @@ namespace gbrainy.Games.Logic
switch (figure) {
case 0:
x = DrawAreaX;
- container1 = new Container (x, y, 0.8, figure_size);
+ container1 = new HorizontalContainer (x, y, 0.8, figure_size);
container = container1;
AddWidget (container);
break;
case 3:
x = DrawAreaX;
y += 0.4;
- container2 = new Container (x, y, 0.8, figure_size);
+ container2 = new HorizontalContainer (x, y, 0.8, figure_size);
container = container2;
AddWidget (container);
break;
@@ -84,12 +84,13 @@ namespace gbrainy.Games.Logic
}
drawable_area = new DrawableArea (box_size, figure_size);
+ drawable_area.SelectedArea = new Rectangle ((box_size - figure_size) / 2, 0, figure_size, figure_size);
drawable_area.Data = figure;
drawable_area.DataEx = GetPossibleAnswer (figure);
switch (random_indices[figure]) {
case 0:
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
DrawTriangle (e.Context, (e.Width - figure_size) / 2, 0);
e.Context.DrawTextCentered (e.Width / 2, figure_size + 0.02,
@@ -97,7 +98,7 @@ namespace gbrainy.Games.Logic
};
break;
case 1:
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
DrawDiamon (e.Context, (e.Width - figure_size) / 2, 0);
e.Context.DrawTextCentered (e.Width / 2, figure_size + 0.02,
@@ -105,7 +106,7 @@ namespace gbrainy.Games.Logic
};
break;
case 2:
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
DrawRectangleWithTriangles (e.Context, (e.Width - figure_size) / 2, 0);
e.Context.DrawTextCentered (e.Width / 2, figure_size + + 0.02,
@@ -113,7 +114,7 @@ namespace gbrainy.Games.Logic
};
break;
case 3:
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
DrawThreeTriangles (e.Context, (e.Width - figure_size) / 2, 0);
e.Context.DrawTextCentered (e.Width / 2, figure_size + + 0.02,
@@ -121,7 +122,7 @@ namespace gbrainy.Games.Logic
};
break;
case answer_index:
- drawable_area.DrawEventHandler += delegate (object sender, Widget.DrawEventArgs e)
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
{
DrawRectangleWithCross (e.Context, (e.Width - figure_size) / 2, 0);
e.Context.DrawTextCentered (e.Width / 2, figure_size + 0.02,
@@ -132,8 +133,7 @@ namespace gbrainy.Games.Logic
container.AddChild (drawable_area);
x += box_size;
- }
-
+ }
}
static private void DrawTriangle (CairoContextEx gr, double x, double y)
diff --git a/src/Games/Logic/PuzzleSquareDots.cs b/src/Games/Logic/PuzzleSquareDots.cs
index e8bc7fb..9ace316 100644
--- a/src/Games/Logic/PuzzleSquareDots.cs
+++ b/src/Games/Logic/PuzzleSquareDots.cs
@@ -23,6 +23,7 @@ using Mono.Unix;
using gbrainy.Core.Main;
using gbrainy.Core.Libraries;
+using gbrainy.Core.Toolkit;
namespace gbrainy.Games.Logic
{
@@ -103,6 +104,27 @@ namespace gbrainy.Games.Logic
possible_answers = new ArrayListIndicesRandom (3);
possible_answers.Initialize ();
+ DrawableArea drawable_area;
+ HorizontalContainer container = new HorizontalContainer (0.05, 0.5, 0.9, figure_size + 0.1);
+ AddWidget (container);
+
+ for (int i = 0; i < possible_answers.Count; i++) {
+
+ drawable_area = new DrawableArea (figure_size + space_figures, figure_size + 0.1);
+ drawable_area.Data = i;
+ drawable_area.DataEx = GetPossibleAnswer (i);
+ drawable_area.SelectedArea = new Rectangle (space_figures / 2, space_figures / 2, figure_size, figure_size);
+
+ container.AddChild (drawable_area);
+
+ drawable_area.DrawEventHandler += delegate (object sender, DrawEventArgs e)
+ {
+ DrawPossibleAnswer (e.Context, space_figures / 2, space_figures / 2, possible_answers [(int)e.Data]);
+ e.Context.DrawTextCentered (space_figures / 2 + figure_size / 2, space_figures + figure_size,
+ GetPossibleFigureAnswer ((int)e.Data));
+ };
+ }
+
for (int i = 0; i < possible_answers.Count; i++) {
if (possible_answers[i] == 0) {
right_answer = GetPossibleAnswer (i);
@@ -172,7 +194,7 @@ namespace gbrainy.Games.Logic
public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
{
- double x = DrawAreaX, y = DrawAreaY;
+ double x = 0.05 + space_figures / 2, y = DrawAreaY;
base.Draw (gr, area_width, area_height, rtl);
@@ -183,16 +205,6 @@ namespace gbrainy.Games.Logic
y += figure_size + 0.10;
gr.MoveTo (x, y - 0.02);
gr.ShowPangoText (Catalog.GetString ("Possible answers are:"));
- gr.Stroke ();
- y += 0.05;
-
- for (int i = 0; i < possible_answers.Count; i++) {
- DrawPossibleAnswer (gr, x, y, possible_answers[i]);
- gr.MoveTo (x, y + figure_size + 0.05);
- gr.ShowPangoText (GetPossibleFigureAnswer (i));
- gr.Stroke ();
- x+= figure_size + space_figures;
- }
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]