gbrainy r381 - trunk/src
- From: jmas svn gnome org
- To: svn-commits-list gnome org
- Subject: gbrainy r381 - trunk/src
- Date: Sun, 29 Jun 2008 13:54:09 +0000 (UTC)
Author: jmas
Date: Sun Jun 29 13:54:09 2008
New Revision: 381
URL: http://svn.gnome.org/viewvc/gbrainy?rev=381&view=rev
Log:
* Game.cs: Move generic drawing operations to CairoContextEx
* CairoContextEx.cs: Background drawing
* SVGImage.cs: SVG image support
* GameDrawingArea.cs: Use the same background always
* Makefile.am: Adds SVGImage.cs
* Puzzle*, Calculation*, Memory.cs: call base.Draw
2008-06-29 Jordi Mas <jmas softcatala org>
Added:
trunk/src/SVGImage.cs
Modified:
trunk/src/CairoContextEx.cs
trunk/src/CalculationArithmetical.cs
trunk/src/CalculationFractions.cs
trunk/src/CalculationGreatestDivisor.cs
trunk/src/CalculationOperator.cs
trunk/src/CalculationTwoNumbers.cs
trunk/src/CalculationWhichNumber.cs
trunk/src/ChangeLog
trunk/src/Game.cs
trunk/src/GameDrawingArea.cs
trunk/src/Makefile.am
trunk/src/Memory.cs
trunk/src/PuzzleBalance.cs
trunk/src/PuzzleBuildTriangle.cs
trunk/src/PuzzleCirclesRectangle.cs
trunk/src/PuzzleClocks.cs
trunk/src/PuzzleCountCircles.cs
trunk/src/PuzzleCountSeries.cs
trunk/src/PuzzleCoverPercentage.cs
trunk/src/PuzzleCube.cs
trunk/src/PuzzleDivideCircle.cs
trunk/src/PuzzleEquation.cs
trunk/src/PuzzleExtraCircle.cs
trunk/src/PuzzleFigureLetter.cs
trunk/src/PuzzleFigurePattern.cs
trunk/src/PuzzleFigures.cs
trunk/src/PuzzleFourSided.cs
trunk/src/PuzzleLines.cs
trunk/src/PuzzleMatrixGroups.cs
trunk/src/PuzzleMatrixNumbers.cs
trunk/src/PuzzleMissingPiece.cs
trunk/src/PuzzleMissingSlice.cs
trunk/src/PuzzleMostInCommon.cs
trunk/src/PuzzleMoveFigure.cs
trunk/src/PuzzleNextFigure.cs
trunk/src/PuzzleNumericRelation.cs
trunk/src/PuzzleNumericSequence.cs
trunk/src/PuzzleOstracism.cs
trunk/src/PuzzlePencil.cs
trunk/src/PuzzlePeopleTable.cs
trunk/src/PuzzleQuadrilaterals.cs
trunk/src/PuzzleSquareDots.cs
trunk/src/PuzzleSquareSheets.cs
trunk/src/PuzzleSquares.cs
trunk/src/PuzzleSquaresAndLetters.cs
trunk/src/PuzzleTetris.cs
trunk/src/PuzzleTriangles.cs
trunk/src/PuzzleTrianglesWithNumbers.cs
Modified: trunk/src/CairoContextEx.cs
==============================================================================
--- trunk/src/CairoContextEx.cs (original)
+++ trunk/src/CairoContextEx.cs Sun Jun 29 13:54:09 2008
@@ -23,7 +23,6 @@
using System.Text;
using System.Runtime.InteropServices;
-
public class CairoContextEx : Cairo.Context
{
public CairoContextEx (IntPtr state) : base (state)
@@ -146,5 +145,23 @@
Fill ();
Restore ();
}
+
+ virtual public void DrawBackground ()
+ {
+ try {
+ using (SVGImage image = new SVGImage (Defines.DATA_DIR + "background.svg"))
+ {
+ Save ();
+ Scale (0.999 / image.Width, 0.999 / image.Height);
+ image.RenderToCairo (Handle);
+ Restore ();
+ }
+
+ } catch {
+ }
+ }
+
}
+
+
Modified: trunk/src/CalculationArithmetical.cs
==============================================================================
--- trunk/src/CalculationArithmetical.cs (original)
+++ trunk/src/CalculationArithmetical.cs Sun Jun 29 13:54:09 2008
@@ -105,10 +105,7 @@
double operand_y = DrawAreaY + 0.2, operand_space = 0.1;
double aligned_pos = 0.58;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
gr.SetLargeFont ();
for (int i = 0; i < operands.Length - 1; i++)
Modified: trunk/src/CalculationFractions.cs
==============================================================================
--- trunk/src/CalculationFractions.cs (original)
+++ trunk/src/CalculationFractions.cs Sun Jun 29 13:54:09 2008
@@ -136,9 +136,8 @@
double x = 0.5 - (fractions_num * fraction_size / 2), y = DrawAreaY + 0.3;
double offset_x = 0.12;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
+
gr.SetLargeFont ();
for (int i = 0; i < fractions_num; i++)
Modified: trunk/src/CalculationGreatestDivisor.cs
==============================================================================
--- trunk/src/CalculationGreatestDivisor.cs (original)
+++ trunk/src/CalculationGreatestDivisor.cs Sun Jun 29 13:54:09 2008
@@ -197,9 +197,8 @@
{
double x = DrawAreaX, y = DrawAreaY + 0.1;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
+
gr.SetLargeFont ();
gr.MoveTo (0.05, y);
Modified: trunk/src/CalculationOperator.cs
==============================================================================
--- trunk/src/CalculationOperator.cs (original)
+++ trunk/src/CalculationOperator.cs Sun Jun 29 13:54:09 2008
@@ -85,11 +85,9 @@
{
double aligned_pos = 0.58;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
- gr.SetLargeFont ();
+ base.Draw (gr, area_width, area_height);
+ gr.SetLargeFont ();
gr.DrawTextAlignedRight (aligned_pos, DrawAreaY + 0.2, number_a.ToString ());
gr.DrawTextAlignedRight (aligned_pos, DrawAreaY + 0.3, number_b.ToString ());
gr.DrawTextAlignedRight (aligned_pos, DrawAreaY + 0.4, number_c.ToString ());
Modified: trunk/src/CalculationTwoNumbers.cs
==============================================================================
--- trunk/src/CalculationTwoNumbers.cs (original)
+++ trunk/src/CalculationTwoNumbers.cs Sun Jun 29 13:54:09 2008
@@ -66,9 +66,8 @@
{
double x = DrawAreaX;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
+
gr.SetLargeFont ();
gr.MoveTo (x, DrawAreaY + 0.2);
Modified: trunk/src/CalculationWhichNumber.cs
==============================================================================
--- trunk/src/CalculationWhichNumber.cs (original)
+++ trunk/src/CalculationWhichNumber.cs Sun Jun 29 13:54:09 2008
@@ -142,9 +142,8 @@
char option;
int indx;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
+
gr.SetLargeFont ();
for (int i = 0; i < options_cnt; i++)
Modified: trunk/src/Game.cs
==============================================================================
--- trunk/src/Game.cs (original)
+++ trunk/src/Game.cs Sun Jun 29 13:54:09 2008
@@ -20,6 +20,7 @@
using System;
using Cairo;
using Mono.Unix;
+using System.Runtime.InteropServices;
abstract public class Game
{
@@ -42,7 +43,6 @@
private bool draw_answer;
private gbrainy application;
private Cairo.Color default_color;
- private Cairo.Color default_background;
protected string right_answer;
protected Random random;
private TimeSpan game_time;
@@ -57,7 +57,6 @@
application = null;
draw_answer = false;
default_color = new Cairo.Color (0, 0, 0);
- default_background = new Color (1, 1, 1);
won = false;
tip_used = false;
difficulty = Difficulty.Medium;
@@ -228,9 +227,19 @@
public abstract void Initialize ();
- public abstract void Draw (CairoContextEx gr, int width, int height);
public virtual void Finish () {}
+
+ public virtual void Draw (CairoContextEx gr, int width, int height)
+ {
+ gr.Scale (width, height);
+ gr.DrawBackground ();
+ gr.Color = new Cairo.Color (0, 0, 0);
+ gr.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Bold);
+ gr.SetNormalFont ();
+ gr.LineWidth = LineWidth;
+ }
+
public virtual void DrawPreview (CairoContextEx gr, int width, int height)
{
Draw (gr, width, height);
@@ -256,36 +265,5 @@
}
return rslt;
}
-
- virtual public void PrepareGC (CairoContextEx gr)
- {
- gr.LineWidth = LineWidth;
- gr.Color = DefaultDrawingColor;
- gr.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Bold);
- gr.SetNormalFont ();
- }
-
- protected void DrawBackground (CairoContextEx gr)
- {
- int columns = 40;
- int rows = 40;
- double rect_w = 1.0 / rows;
- double rect_h = 1.0 / columns;
-
- gr.Save ();
-
- gr.Color = default_background;
- gr.Paint ();
-
- gr.Color = new Cairo.Color (0.9, 0.9, 0.9);
- gr.LineWidth = 0.001;
- for (int column = 0; column < columns; column++) {
- for (int row = 0; row < rows; row++) {
- gr.Rectangle (row * rect_w, column * rect_h, rect_w, rect_h);
- }
- }
- gr.Stroke ();
- gr.Restore ();
- }
}
Modified: trunk/src/GameDrawingArea.cs
==============================================================================
--- trunk/src/GameDrawingArea.cs (original)
+++ trunk/src/GameDrawingArea.cs Sun Jun 29 13:54:09 2008
@@ -88,7 +88,7 @@
ImageSurface image;
gr.Scale (area_width, area_height);
- DrawBackground (gr);
+ gr.DrawBackground ();
gr.Color = new Cairo.Color (0, 0, 0, 1);
gr.Save ();
gr.SetFontSize (0.035);
@@ -264,8 +264,7 @@
string s;
gr.Scale (area_width, area_height);
- gr.Color = new Cairo.Color (1, 1, 1);
- gr.Paint ();
+ gr.DrawBackground ();
gr.Color = new Cairo.Color (0, 0, 0, 1);
gr.SetFontSize (0.03);
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Sun Jun 29 13:54:09 2008
@@ -66,6 +66,7 @@
$(srcdir)/GtkDialog.cs \
$(srcdir)/Preferences.cs \
$(srcdir)/PuzzleFourSided.cs \
+ $(srcdir)/SVGImage.cs \
$(srcdir)/gbrainy.cs
ASSEMBLIES = \
Modified: trunk/src/Memory.cs
==============================================================================
--- trunk/src/Memory.cs (original)
+++ trunk/src/Memory.cs Sun Jun 29 13:54:09 2008
@@ -115,9 +115,7 @@
public override void Draw (CairoContextEx gr, int area_width, int area_height)
{
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
if (shade) {
if (alpha > 0)
@@ -140,9 +138,10 @@
public override void DrawPreview (CairoContextEx gr, int width, int height)
{
gr.Scale (width, height);
- DrawBackground (gr);
- PrepareGC (gr);
- DrawObjectToMemorize (gr, width, height);
+ gr.DrawBackground ();
+ gr.Color = new Cairo.Color (0, 0, 0);
+ gr.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Bold);
+ gr.SetNormalFont ();
}
public virtual void DrawPossibleAnswers (CairoContextEx gr, int area_width, int area_height) {}
Modified: trunk/src/PuzzleBalance.cs
==============================================================================
--- trunk/src/PuzzleBalance.cs (original)
+++ trunk/src/PuzzleBalance.cs Sun Jun 29 13:54:09 2008
@@ -125,9 +125,7 @@
{
double x = 0.05, y = DrawAreaY + 0.1;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
DrawBalance (gr, x, y, group * elements * 6, true);
y += 0.3;
Modified: trunk/src/PuzzleBuildTriangle.cs
==============================================================================
--- trunk/src/PuzzleBuildTriangle.cs (original)
+++ trunk/src/PuzzleBuildTriangle.cs Sun Jun 29 13:54:09 2008
@@ -142,9 +142,7 @@
double x = DrawAreaX + 0.05, y = DrawAreaY + 0.05;
double degrees, x1, x2, dist;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int i = 0; i < random_indices_answers.Count; i++)
{
Modified: trunk/src/PuzzleCirclesRectangle.cs
==============================================================================
--- trunk/src/PuzzleCirclesRectangle.cs (original)
+++ trunk/src/PuzzleCirclesRectangle.cs Sun Jun 29 13:54:09 2008
@@ -62,10 +62,8 @@
int circles = 8;
double unit = 0.0625;
- gr.Scale (area_width, area_height);
+ base.Draw (gr, area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
gr.Rectangle (first_x, first_y, unit * 8, unit * 8);
gr.Stroke ();
Modified: trunk/src/PuzzleClocks.cs
==============================================================================
--- trunk/src/PuzzleClocks.cs (original)
+++ trunk/src/PuzzleClocks.cs Sun Jun 29 13:54:09 2008
@@ -147,11 +147,8 @@
{
double x = DrawAreaX + 0.1, y = DrawAreaY + 0.05;
- gr.Scale (area_width, area_height);
+ base.Draw (gr, area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
-
DrawClock (gr, x + 0.1, y + 0.1, handles[0], handles[1], true);
gr.MoveTo (x + 0.03, y + 0.31);
gr.ShowText (String.Format (Catalog.GetString ("Figure {0}"), 'A'));
Modified: trunk/src/PuzzleCountCircles.cs
==============================================================================
--- trunk/src/PuzzleCountCircles.cs (original)
+++ trunk/src/PuzzleCountCircles.cs Sun Jun 29 13:54:09 2008
@@ -89,9 +89,7 @@
{
double x = DrawAreaX + 0.1, y = DrawAreaY + 0.05;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int i = 0; i < circles.Length; i++)
{
Modified: trunk/src/PuzzleCountSeries.cs
==============================================================================
--- trunk/src/PuzzleCountSeries.cs (original)
+++ trunk/src/PuzzleCountSeries.cs Sun Jun 29 13:54:09 2008
@@ -73,8 +73,7 @@
public override void Draw (CairoContextEx gr, int area_width, int area_height)
{
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
+ base.Draw (gr, area_width, area_height);
}
}
Modified: trunk/src/PuzzleCoverPercentage.cs
==============================================================================
--- trunk/src/PuzzleCoverPercentage.cs (original)
+++ trunk/src/PuzzleCoverPercentage.cs Sun Jun 29 13:54:09 2008
@@ -112,10 +112,7 @@
{
double x = 0.25, y = 0.25;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
gr.Rectangle (x, y, width, height);
gr.Stroke ();
Modified: trunk/src/PuzzleCube.cs
==============================================================================
--- trunk/src/PuzzleCube.cs (original)
+++ trunk/src/PuzzleCube.cs Sun Jun 29 13:54:09 2008
@@ -56,10 +56,7 @@
double txtoff_x = 0.04;
double txtoff_y = 0.06;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
gr.Rectangle (x + 0.1, y, 0.1, 0.1);
gr.MoveTo (x + 0.1 + txtoff_x, y + txtoff_y);
Modified: trunk/src/PuzzleDivideCircle.cs
==============================================================================
--- trunk/src/PuzzleDivideCircle.cs (original)
+++ trunk/src/PuzzleDivideCircle.cs Sun Jun 29 13:54:09 2008
@@ -95,10 +95,7 @@
double pos_y = y;
Circle[] circles = null;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
// First circle
gr.Arc (pos_x + figure_size, y + figure_size, figure_size, 0, 2 * Math.PI);
Modified: trunk/src/PuzzleEquation.cs
==============================================================================
--- trunk/src/PuzzleEquation.cs (original)
+++ trunk/src/PuzzleEquation.cs Sun Jun 29 13:54:09 2008
@@ -66,10 +66,8 @@
public override void Draw (CairoContextEx gr, int area_width, int area_height)
{
- gr.Scale (area_width, area_height);
+ base.Draw (gr, area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
gr.SetLargeFont ();
gr.DrawTextCentered (0.5, DrawAreaY + 0.3, formula);
}
Modified: trunk/src/PuzzleExtraCircle.cs
==============================================================================
--- trunk/src/PuzzleExtraCircle.cs (original)
+++ trunk/src/PuzzleExtraCircle.cs Sun Jun 29 13:54:09 2008
@@ -136,9 +136,7 @@
double x = DrawAreaX, y = DrawAreaY;
Color [] colors;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
x+= radius / 2;
y+= radius / 2;
Modified: trunk/src/PuzzleFigureLetter.cs
==============================================================================
--- trunk/src/PuzzleFigureLetter.cs (original)
+++ trunk/src/PuzzleFigureLetter.cs Sun Jun 29 13:54:09 2008
@@ -114,11 +114,8 @@
double x = DrawAreaX + 0.05;
double y = DrawAreaY + 0.1;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
-
+ base.Draw (gr, area_width, area_height);
+
// Three circles
gr.Arc (x + 0.06, y, 0.05, 0, 2 * Math.PI);
gr.Stroke ();
Modified: trunk/src/PuzzleFigurePattern.cs
==============================================================================
--- trunk/src/PuzzleFigurePattern.cs (original)
+++ trunk/src/PuzzleFigurePattern.cs Sun Jun 29 13:54:09 2008
@@ -101,9 +101,7 @@
double figure_size = 0.13, space_x = 0.1, space_y = 0.2;
double x45, y45, x135, y135, offset;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
// First pattern
gr.Rectangle (x, y, figure_size, figure_size);
Modified: trunk/src/PuzzleFigures.cs
==============================================================================
--- trunk/src/PuzzleFigures.cs (original)
+++ trunk/src/PuzzleFigures.cs Sun Jun 29 13:54:09 2008
@@ -108,9 +108,7 @@
double figure_width = 0.1, figure_height = 0.1, space_width = 0.05, space_height = 0.1;
double x = DrawAreaX, y = DrawAreaY;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int i = 0; i < (DrawAnswer ? 6 : 5) ; i++)
{
Modified: trunk/src/PuzzleFourSided.cs
==============================================================================
--- trunk/src/PuzzleFourSided.cs (original)
+++ trunk/src/PuzzleFourSided.cs Sun Jun 29 13:54:09 2008
@@ -67,9 +67,7 @@
{
double x = DrawAreaX + 0.1, y = DrawAreaY + 0.1, w = 0.6, h = 0.6;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
gr.Rectangle (x, y, w, h);
gr.Stroke ();
Modified: trunk/src/PuzzleLines.cs
==============================================================================
--- trunk/src/PuzzleLines.cs (original)
+++ trunk/src/PuzzleLines.cs Sun Jun 29 13:54:09 2008
@@ -81,10 +81,7 @@
public override void Draw (CairoContextEx gr, int area_width, int area_height)
{
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
DrawLine (gr, 0.1, 0.2, 0.4, 0.38);
DrawLine (gr, 0.1, 0.3, 0.4, 0.3);
Modified: trunk/src/PuzzleMatrixGroups.cs
==============================================================================
--- trunk/src/PuzzleMatrixGroups.cs (original)
+++ trunk/src/PuzzleMatrixGroups.cs Sun Jun 29 13:54:09 2008
@@ -108,10 +108,8 @@
double rect_w = DrawAreaWidth / rows;
double rect_h = DrawAreaHeight / columns;
- gr.Scale (area_width, area_height);
+ base.Draw (gr, area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
for (int column = 0; column < columns; column++) {
for (int row = 0; row < rows; row++) {
Modified: trunk/src/PuzzleMatrixNumbers.cs
==============================================================================
--- trunk/src/PuzzleMatrixNumbers.cs (original)
+++ trunk/src/PuzzleMatrixNumbers.cs Sun Jun 29 13:54:09 2008
@@ -131,10 +131,7 @@
double rect_w = DrawAreaWidth / rows;
double rect_h = DrawAreaHeight / columns;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int column = 0; column < columns; column++) {
for (int row = 0; row < rows; row++) {
Modified: trunk/src/PuzzleMissingPiece.cs
==============================================================================
--- trunk/src/PuzzleMissingPiece.cs (original)
+++ trunk/src/PuzzleMissingPiece.cs Sun Jun 29 13:54:09 2008
@@ -136,9 +136,7 @@
double x = DrawAreaX + 0.15, y = DrawAreaY;
int figure;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int i = 0; i < 2; i++)
DrawFigureSequence (gr, x, y + sub_figure * i , i, true);
Modified: trunk/src/PuzzleMissingSlice.cs
==============================================================================
--- trunk/src/PuzzleMissingSlice.cs (original)
+++ trunk/src/PuzzleMissingSlice.cs Sun Jun 29 13:54:09 2008
@@ -139,9 +139,7 @@
double x0, y0, degrees;
int pos;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
gr.Arc (x + arc_centerx, y + arc_centery, radius, 0, 2 * Math.PI);
gr.Stroke ();
Modified: trunk/src/PuzzleMostInCommon.cs
==============================================================================
--- trunk/src/PuzzleMostInCommon.cs (original)
+++ trunk/src/PuzzleMostInCommon.cs Sun Jun 29 13:54:09 2008
@@ -269,9 +269,7 @@
{
double x = DrawAreaX, y = DrawAreaY + 0.1;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int i = 0; i < questions.Count; i++) {
DrawFigure (gr, x, y, (FigureElement []) questions[i]);
Modified: trunk/src/PuzzleMoveFigure.cs
==============================================================================
--- trunk/src/PuzzleMoveFigure.cs (original)
+++ trunk/src/PuzzleMoveFigure.cs Sun Jun 29 13:54:09 2008
@@ -73,9 +73,7 @@
double figure_size = 0.07 + (0.01 * (5 - lines));
double margin = 0;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
// Figure 1
margin = ((1.0 - (figure_size * lines * 2)) / 2);
Modified: trunk/src/PuzzleNextFigure.cs
==============================================================================
--- trunk/src/PuzzleNextFigure.cs (original)
+++ trunk/src/PuzzleNextFigure.cs Sun Jun 29 13:54:09 2008
@@ -112,10 +112,8 @@
double x = DrawAreaX;
double y = DrawAreaY;
double space_figures = figure_size + 0.1;
-
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+
+ base.Draw (gr, area_width, area_height);
DrawDiamon (gr, x, y, CerclePosition.Top | CerclePosition.Left);
DrawDiamon (gr, x + space_figures , y, CerclePosition.Bottom);
Modified: trunk/src/PuzzleNumericRelation.cs
==============================================================================
--- trunk/src/PuzzleNumericRelation.cs (original)
+++ trunk/src/PuzzleNumericRelation.cs Sun Jun 29 13:54:09 2008
@@ -108,9 +108,8 @@
{
StringBuilder sequence = new StringBuilder (64);
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
+
gr.SetLargeFont ();
for (int num = 0; num < max_num - 1; num++)
Modified: trunk/src/PuzzleNumericSequence.cs
==============================================================================
--- trunk/src/PuzzleNumericSequence.cs (original)
+++ trunk/src/PuzzleNumericSequence.cs Sun Jun 29 13:54:09 2008
@@ -86,9 +86,7 @@
{
StringBuilder sequence = new StringBuilder (64);
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
gr.SetLargeFont ();
for (int num = 0; num < max_num - 1; num++)
Modified: trunk/src/PuzzleOstracism.cs
==============================================================================
--- trunk/src/PuzzleOstracism.cs (original)
+++ trunk/src/PuzzleOstracism.cs Sun Jun 29 13:54:09 2008
@@ -74,11 +74,9 @@
{
double x = DrawAreaX + 0.15, y = DrawAreaY + 0.2;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
- gr.SetLargeFont ();
-
+ base.Draw (gr, area_width, area_height);
+
+ gr.SetLargeFont ();
for (int i = 0; i < random_indices.Count; i++)
{
gr.MoveTo (x, y);
Modified: trunk/src/PuzzlePencil.cs
==============================================================================
--- trunk/src/PuzzlePencil.cs (original)
+++ trunk/src/PuzzlePencil.cs Sun Jun 29 13:54:09 2008
@@ -136,9 +136,7 @@
{
double x = DrawAreaX, y = DrawAreaY;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int figure = 0; figure < figures; figure++)
{
Modified: trunk/src/PuzzlePeopleTable.cs
==============================================================================
--- trunk/src/PuzzlePeopleTable.cs (original)
+++ trunk/src/PuzzlePeopleTable.cs Sun Jun 29 13:54:09 2008
@@ -82,11 +82,8 @@
double pos_y = y;
Circle[] circles = null;
- gr.Scale (area_width, area_height);
+ base.Draw (gr, area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
-
circles = new Circle [] {
new Circle (0.01, 0.06),
new Circle (0.27, 0.06),
Modified: trunk/src/PuzzleQuadrilaterals.cs
==============================================================================
--- trunk/src/PuzzleQuadrilaterals.cs (original)
+++ trunk/src/PuzzleQuadrilaterals.cs Sun Jun 29 13:54:09 2008
@@ -131,10 +131,7 @@
{
double x = DrawAreaX, y = DrawAreaY, space_x = 0.15;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int i = 0; i < random_indices.Count; i++) {
DrawFigure (gr, x, y, (Figures) random_indices[i]);
Modified: trunk/src/PuzzleSquareDots.cs
==============================================================================
--- trunk/src/PuzzleSquareDots.cs (original)
+++ trunk/src/PuzzleSquareDots.cs Sun Jun 29 13:54:09 2008
@@ -167,10 +167,8 @@
{
double x = DrawAreaX, y = DrawAreaY;
- gr.Scale (area_width, area_height);
+ base.Draw (gr, area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
DrawFigure (gr, x, y, puzzle_A, 0);
DrawFigure (gr, x + figure_size + space_figures, y, puzzle_A, columns * lines);
DrawFigure (gr, x + (figure_size + space_figures) * 2, y, puzzle_A, columns * lines * 2);
Modified: trunk/src/PuzzleSquareSheets.cs
==============================================================================
--- trunk/src/PuzzleSquareSheets.cs (original)
+++ trunk/src/PuzzleSquareSheets.cs Sun Jun 29 13:54:09 2008
@@ -53,10 +53,7 @@
{
double x = DrawAreaX + 0.2, y = DrawAreaY + 0.2, width = 0.4, height = 0.4;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
gr.Rectangle (x, y, width, height);
gr.Stroke ();
Modified: trunk/src/PuzzleSquares.cs
==============================================================================
--- trunk/src/PuzzleSquares.cs (original)
+++ trunk/src/PuzzleSquares.cs Sun Jun 29 13:54:09 2008
@@ -77,10 +77,7 @@
double rect_w = DrawAreaWidth / rows;
double rect_h = DrawAreaHeight / columns;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int column = 0; column < columns; column++) {
for (int row = 0; row < rows; row++) {
Modified: trunk/src/PuzzleSquaresAndLetters.cs
==============================================================================
--- trunk/src/PuzzleSquaresAndLetters.cs (original)
+++ trunk/src/PuzzleSquaresAndLetters.cs Sun Jun 29 13:54:09 2008
@@ -99,9 +99,7 @@
{
double x = DrawAreaX + 0.05, y = DrawAreaY + 0.1;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
DrawRectangleWithText (gr, x, y, 0);
DrawRectangleWithText (gr, x + figure_size + 0.2, y, 4);
Modified: trunk/src/PuzzleTetris.cs
==============================================================================
--- trunk/src/PuzzleTetris.cs (original)
+++ trunk/src/PuzzleTetris.cs Sun Jun 29 13:54:09 2008
@@ -135,10 +135,7 @@
{
double x = DrawAreaX, y = DrawAreaY + 0.1;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
for (int i = 0; i < 4; i++) {
DrawQuestionFigures (gr, x, y, random_indices_questions [i]);
Modified: trunk/src/PuzzleTriangles.cs
==============================================================================
--- trunk/src/PuzzleTriangles.cs (original)
+++ trunk/src/PuzzleTriangles.cs Sun Jun 29 13:54:09 2008
@@ -67,10 +67,7 @@
double x = DrawAreaX + 0.1, y = DrawAreaY + 0.2;
double witdh = 0.6, height = 0.5;
- gr.Scale (area_width, area_height);
-
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
gr.MoveTo (x, y);
gr.LineTo (x + witdh, y);
Modified: trunk/src/PuzzleTrianglesWithNumbers.cs
==============================================================================
--- trunk/src/PuzzleTrianglesWithNumbers.cs (original)
+++ trunk/src/PuzzleTrianglesWithNumbers.cs Sun Jun 29 13:54:09 2008
@@ -115,9 +115,7 @@
{
double x = DrawAreaX, y = DrawAreaY + 0.1;
- gr.Scale (area_width, area_height);
- DrawBackground (gr);
- PrepareGC (gr);
+ base.Draw (gr, area_width, area_height);
DrawTriangle (gr, x, y, 0, false);
x += 0.3;
Added: trunk/src/SVGImage.cs
==============================================================================
--- (empty file)
+++ trunk/src/SVGImage.cs Sun Jun 29 13:54:09 2008
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2008 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 Cairo;
+using Mono.Unix;
+using System.IO;
+using System.Runtime.InteropServices;
+
+//
+// SVG image class based on rsvg library
+//
+public class SVGImage : IDisposable
+{
+ //lib rsvg2
+ [DllImport("rsvg-2")]
+ static extern void rsvg_handle_render_cairo (IntPtr Rsvghandle, IntPtr cairo_t);
+
+ [DllImport("rsvg-2")]
+ static extern IntPtr rsvg_handle_new_from_file (string file_name, out int error);
+
+ [DllImport("rsvg-2")]
+ static extern void rsvg_handle_free (IntPtr handle);
+
+ [DllImport("rsvg-2")]
+ static extern void rsvg_handle_get_dimensions (IntPtr handle, ref RsvgDimensionData dimension);
+
+ [StructLayout(LayoutKind.Sequential)]
+ protected struct RsvgDimensionData
+ {
+ public int width;
+ public int height;
+ public double em;
+ public double ex;
+ }
+
+ private RsvgDimensionData dimension;
+ private IntPtr handle;
+
+ public SVGImage (string file)
+ {
+ int error = 0;
+
+ handle = rsvg_handle_new_from_file (file, out error);
+
+ if (handle == IntPtr.Zero)
+ throw new System.IO.IOException ("File not found: " + file);
+
+ dimension = new RsvgDimensionData ();
+ rsvg_handle_get_dimensions (handle, ref dimension);
+ }
+
+ public int Width {
+ get { return dimension.width; }
+ }
+
+ public int Height {
+ get { return dimension.height; }
+ }
+
+ public void Dispose ()
+ {
+ if (handle == IntPtr.Zero)
+ return;
+
+ rsvg_handle_free (handle);
+ handle = IntPtr.Zero;
+ }
+
+ public void RenderToCairo (IntPtr cairo_surface)
+ {
+ rsvg_handle_render_cairo (handle, cairo_surface);
+ }
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]