Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/gcompris/score.c
blob: b2da2c8570e13613d6176cce1202c4007fa3deac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* gcompris - score.c
 *
 * Copyright (C) 2000 Bruno Coudoin
 *
 *   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 3 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, see <http://www.gnu.org/licenses/>.
 */

/**
 * This includes an API to count scores in gcompris
 *
 */

#include "gcompris.h"

static GnomeCanvasGroup *boardRootItem = NULL;

static guint x, y, max;
static ScoreStyleList currentStyle;

/*
 * Forward declarations
 */
static void display_number(GnomeCanvasGroup *parent,
			   guint x,
			   guint y,
			   char *operand_str);

/*
 * Main entry score
 * ----------------
 *
 */


/*
 * Do all the score display
 */
void
gc_score_start (ScoreStyleList style, guint gx, guint gy, guint gmax)
{

  currentStyle = style;
  x = gx;
  y = gy;
  max = gmax;


  switch(currentStyle) {
  case SCORESTYLE_NOTE :
    break;
  default:
    break;
  }
}


void
gc_score_end()
{
  if(boardRootItem!=NULL)
    gtk_object_destroy (GTK_OBJECT(boardRootItem));

  boardRootItem=NULL;
}

void
gc_score_set(guint value)
{

  if(boardRootItem!=NULL)
    gtk_object_destroy (GTK_OBJECT(boardRootItem));

  boardRootItem = GNOME_CANVAS_GROUP(
				     gnome_canvas_item_new (
							    gnome_canvas_root(gc_board_get_current()->canvas),
							    gnome_canvas_group_get_type (),
							    "x", (double) x,
							    "y", (double) y,
							    NULL));

  switch(currentStyle) {
  case SCORESTYLE_NOTE :
    {
      gchar *tmp;
      GdkPixbuf *button_pixmap = NULL;

      button_pixmap = gc_skin_pixmap_load("button_large.png");
      gnome_canvas_item_new (boardRootItem,
			     gnome_canvas_pixbuf_get_type (),
			     "pixbuf",  button_pixmap,
			     "x",  (double) 0,
			     "y",  (double) -gdk_pixbuf_get_height(button_pixmap)/2,
			     NULL);
      gdk_pixbuf_unref(button_pixmap);

      tmp = g_strdup_printf("%d/%d", value, max);
      display_number(boardRootItem, gdk_pixbuf_get_width(button_pixmap)+10, 0, tmp);
      g_free(tmp);
    }
    break;
  default:
    break;
  }
}

/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/


#define NUMBERSWIDTH       110

static void
display_number(GnomeCanvasGroup *parent,
	       guint x,
	       guint y,
	       char *operand_str)
{

  x -= NUMBERSWIDTH;

  gnome_canvas_item_new (parent,
			 gnome_canvas_text_get_type (),
			 "text", operand_str,
			 "font", gc_skin_font_board_huge_bold,
			 "x", (double) x+2,
			 "y", (double) y+2,
			 "anchor", GTK_ANCHOR_CENTER,
			 "fill_color_rgba", 0x7a8699FF,
			 NULL);
  gnome_canvas_item_new (parent,
			 gnome_canvas_text_get_type (),
			 "text", operand_str,
			 "font", gc_skin_font_board_huge_bold,
			 "x", (double) x,
			 "y", (double) y,
			 "anchor", GTK_ANCHOR_CENTER,
			 "fill_color_rgba", 0xe5e532FF,
			 NULL);
}