~ubuntu-branches/ubuntu/trusty/gcompris/trusty

« back to all changes in this revision

Viewing changes to src/gcompris/score.c

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2002-04-21 16:16:27 UTC
  • Revision ID: james.westby@ubuntu.com-20020421161627-s07yahahm817qxs6
Tags: upstream-1.0.3
ImportĀ upstreamĀ versionĀ 1.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gcompris - score.c
 
2
 *
 
3
 * Time-stamp: <2001/12/02 22:19:10 bruno>
 
4
 *
 
5
 * Copyright (C) 2000 Bruno Coudoin
 
6
 *
 
7
 *   This program is free software; you can redistribute it and/or modify
 
8
 *   it under the terms of the GNU General Public License as published by
 
9
 *   the Free Software Foundation; either version 2 of the License, or
 
10
 *   (at your option) any later version.
 
11
 *
 
12
 *   This program is distributed in the hope that it will be useful,
 
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *   GNU General Public License for more details.
 
16
 *
 
17
 *   You should have received a copy of the GNU General Public License
 
18
 *   along with this program; if not, write to the Free Software
 
19
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
20
 */
 
21
 
 
22
/**
 
23
 * This includes an API to count scores in gcompris
 
24
 *
 
25
 */
 
26
 
 
27
#include "gcompris.h"
 
28
 
 
29
static GnomeCanvasGroup *boardRootItem = NULL;
 
30
 
 
31
static guint x, y, max;
 
32
static ScoreStyleList currentStyle;
 
33
 
 
34
/*
 
35
 * Forward declarations
 
36
 */
 
37
static void display_number(GnomeCanvasGroup *parent, 
 
38
                           guint x,
 
39
                           guint y, 
 
40
                           char *operand_str);
 
41
 
 
42
/*
 
43
 * Main entry score 
 
44
 * ----------------
 
45
 *
 
46
 */
 
47
 
 
48
 
 
49
/*
 
50
 * Do all the score display
 
51
 */
 
52
void gcompris_score_start (ScoreStyleList style, guint gx, guint gy, guint gmax)
 
53
{
 
54
 
 
55
  currentStyle = style;
 
56
  x = gx;
 
57
  y = gy;
 
58
  max = gmax;
 
59
 
 
60
 
 
61
  switch(currentStyle) {
 
62
  case SCORESTYLE_NOTE :
 
63
    break;
 
64
  default:
 
65
    break;
 
66
  }
 
67
}
 
68
 
 
69
 
 
70
void gcompris_score_end()
 
71
{
 
72
  if(boardRootItem!=NULL)
 
73
    gtk_object_destroy (GTK_OBJECT(boardRootItem));
 
74
  
 
75
  boardRootItem=NULL;
 
76
}
 
77
 
 
78
void gcompris_score_set(guint value)
 
79
{
 
80
 
 
81
  if(boardRootItem!=NULL)
 
82
    gtk_object_destroy (GTK_OBJECT(boardRootItem));
 
83
 
 
84
  boardRootItem = GNOME_CANVAS_GROUP(
 
85
                                     gnome_canvas_item_new (
 
86
                                                            gnome_canvas_root(get_current_gcompris_board()->canvas),
 
87
                                                            gnome_canvas_group_get_type (),
 
88
                                                            "x", (double) x,
 
89
                                                            "y", (double) y,
 
90
                                                            NULL));
 
91
 
 
92
  switch(currentStyle) {
 
93
  case SCORESTYLE_NOTE :
 
94
    {
 
95
      gchar *tmp;
 
96
      GdkPixbuf *button_pixmap = NULL;
 
97
 
 
98
      button_pixmap = gcompris_load_pixmap("gcompris/buttons/button_large.png");
 
99
      gnome_canvas_item_new (boardRootItem,
 
100
                             gnome_canvas_pixbuf_get_type (),
 
101
                             "pixbuf",  button_pixmap,
 
102
                             "x",  (double) 0,
 
103
                             "y",  (double) -gdk_pixbuf_get_height(button_pixmap)/2,
 
104
                             NULL);
 
105
      gdk_pixbuf_unref(button_pixmap);
 
106
 
 
107
      tmp = g_strdup_printf("%d:%d", value, max);
 
108
      display_number(boardRootItem, gdk_pixbuf_get_width(button_pixmap)+20, 0, tmp);
 
109
      g_free(tmp);
 
110
    }
 
111
    break;
 
112
  default:
 
113
    break;
 
114
  }
 
115
}
 
116
 
 
117
/*-------------------------------------------------------------------------------*/
 
118
/*-------------------------------------------------------------------------------*/
 
119
/*-------------------------------------------------------------------------------*/
 
120
/*-------------------------------------------------------------------------------*/
 
121
 
 
122
 
 
123
#define NUMBERSWIDTH       35
 
124
#define NUMBERGAP          0
 
125
#define ZOOMFACTOR         0.8
 
126
 
 
127
static void display_number(GnomeCanvasGroup *parent, 
 
128
                           guint x,
 
129
                           guint y, 
 
130
                           char *operand_str)
 
131
{
 
132
  GdkPixbuf *algebra_pixmap = NULL;
 
133
  GnomeCanvasItem *item;
 
134
  int i;
 
135
 
 
136
  x -= NUMBERSWIDTH/2 + 15;
 
137
 
 
138
  for(i=strlen(operand_str)-1; i>=0; i--)
 
139
    {
 
140
      guint gap;
 
141
 
 
142
      algebra_pixmap = gcompris_load_number_pixmap(operand_str[i]);
 
143
 
 
144
      // Calculate a gap to center the text
 
145
      gap = (5-strlen(operand_str))*(NUMBERSWIDTH+NUMBERGAP)/2;
 
146
 
 
147
      item = gnome_canvas_item_new (parent,
 
148
                                    gnome_canvas_pixbuf_get_type (),
 
149
                                    "pixbuf", algebra_pixmap, 
 
150
                                    "x", (double)x-gap-((strlen(operand_str)-i)*(NUMBERSWIDTH+NUMBERGAP)),
 
151
                                    "y", (double)y - gdk_pixbuf_get_height(algebra_pixmap)*ZOOMFACTOR/2,
 
152
                                    "width", (double) NUMBERSWIDTH,
 
153
                                    "height", (double) gdk_pixbuf_get_height(algebra_pixmap)*ZOOMFACTOR,
 
154
                                    "width_set", TRUE, 
 
155
                                    "height_set", TRUE,
 
156
                                    NULL);
 
157
      gdk_pixbuf_unref(algebra_pixmap);
 
158
    }
 
159
}
 
160
 
 
161
 
 
162
 
 
163
/* Local Variables: */
 
164
/* mode:c */
 
165
/* eval:(load-library "time-stamp") */
 
166
/* eval:(make-local-variable 'write-file-hooks) */
 
167
/* eval:(add-hook 'write-file-hooks 'time-stamp) */
 
168
/* eval:(setq time-stamp-format '(time-stamp-yyyy/mm/dd time-stamp-hh:mm:ss user-login-name)) */
 
169
/* End: */