~ubuntu-branches/ubuntu/lucid/gbrainy/lucid

« back to all changes in this revision

Viewing changes to src/Core/Main/Verbal/AnalogiesMultipleOptions.cs

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2010-01-12 11:21:24 UTC
  • mfrom: (13.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100112112124-o4ztomxa0xfh2ulj
Tags: 1.30-1ubuntu1
* debian/control:
  - Revert build-depends to lucid versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2009 Jordi Mas i Hernàndez <jmas@softcatala.org>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; either version 2 of the
 
7
 * License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public
 
15
 * License along with this program; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
using System;
 
21
using System.IO;
 
22
using System.Collections.Generic;
 
23
 
 
24
using Cairo;
 
25
using Mono.Unix;
 
26
 
 
27
using gbrainy.Core.Libraries;
 
28
 
 
29
namespace gbrainy.Core.Main.Verbal
 
30
{
 
31
        public class AnalogiesMultipleOptions : Analogies
 
32
        {
 
33
                static protected Dictionary <int, Analogy> analogies;
 
34
                static protected ArrayListIndicesRandom analogies_indices;
 
35
                static protected int analogies_index = 0;
 
36
 
 
37
                public AnalogiesMultipleOptions ()
 
38
                {
 
39
                        if (analogies == null)
 
40
                                analogies = AnalogiesFactory. Get (Analogy.Type.MultipleOptions);
 
41
                }
 
42
 
 
43
                public override string Name {
 
44
                        get { return Catalog.GetString ("Multiple options");}
 
45
                }
 
46
 
 
47
                public override string Question {
 
48
                        get {
 
49
                                string str = string.Empty;
 
50
 
 
51
                                if (current == null)
 
52
                                        return string.Empty;
 
53
 
 
54
                                if (current.answers == null)
 
55
                                        return current.question;
 
56
 
 
57
                                for (int n = 0; n < current.answers.Length; n++)
 
58
                                {
 
59
                                        str+= GetPossibleAnswer (n);
 
60
 
 
61
                                        if (n +1 < current.answers.Length) {
 
62
                                                // Translators: this the separator used when concatenating possible options for answering verbal analogies
 
63
                                                // For example: "Possible correct answers are: a, b, c, d."                                             
 
64
                                                str += Catalog.GetString (", ");
 
65
                                        }
 
66
                                }
 
67
 
 
68
                                // Translators: {0} is replaced by a question and {1} by the suggestions on how to answer
 
69
                                // E.g: What is the correct option? Answer A, B, C.
 
70
                                return String.Format (Catalog.GetString ("{0} Answer {1}."),
 
71
                                        current.question,
 
72
                                        str);
 
73
                        }
 
74
                }
 
75
 
 
76
                public override ArrayListIndicesRandom Indices {
 
77
                        get { return analogies_indices; }
 
78
                        set { analogies_indices = value; }
 
79
                }
 
80
 
 
81
                public override int CurrentIndex {
 
82
                        get { return analogies_index; }
 
83
                        set { analogies_index = value; }
 
84
                }
 
85
 
 
86
                public override Dictionary <int, Analogy> List {
 
87
                        get { return analogies; }
 
88
                }
 
89
 
 
90
                public override void Initialize ()
 
91
                {
 
92
                        current = GetNext ();
 
93
 
 
94
                        if (current == null || current.answers == null)
 
95
                                return;
 
96
 
 
97
                        right_answer = GetPossibleAnswer (current.right);
 
98
                }
 
99
        
 
100
                public override void Draw (CairoContextEx gr, int area_width, int area_height, bool rtl)
 
101
                {
 
102
                        double x = DrawAreaX, y = DrawAreaY + 0.1;
 
103
 
 
104
                        base.Draw (gr, area_width, area_height, rtl);
 
105
 
 
106
                        if (current == null || current.answers == null)
 
107
                                return;
 
108
 
 
109
                        gr.SetPangoLargeFontSize ();
 
110
                        gr.MoveTo (0.1, y);
 
111
                        gr.ShowPangoText (Catalog.GetString ("Possible answers are:"));
 
112
 
 
113
                        gr.SetPangoNormalFontSize ();
 
114
 
 
115
                        y += 0.15;
 
116
                        x += 0.05;
 
117
                        for (int n = 0; n < current.answers.Length; n++)
 
118
                        {
 
119
                                gr.MoveTo (x, y);
 
120
                                gr.ShowPangoText (String.Format ("{0}) {1}", GetPossibleAnswer (n), current.answers[n].ToString ()));
 
121
                                gr.Stroke ();
 
122
                                y += 0.15;
 
123
                        }
 
124
                }
 
125
        }
 
126
}