Back to index

gcompris  8.2.2
score.c
Go to the documentation of this file.
00001 /* gcompris - score.c
00002  *
00003  * Time-stamp: <2006/08/21 23:27:04 bruno>
00004  *
00005  * Copyright (C) 2000 Bruno Coudoin
00006  *
00007  *   This program is free software; you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation; either version 2 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with this program; if not, write to the Free Software
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00027 #include "gcompris.h"
00028 
00029 static GnomeCanvasGroup *boardRootItem = NULL;
00030 
00031 static guint x, y, max;
00032 static ScoreStyleList currentStyle;
00033 
00034 /*
00035  * Forward declarations
00036  */
00037 static void display_number(GnomeCanvasGroup *parent, 
00038                         guint x,
00039                         guint y, 
00040                         char *operand_str);
00041 
00042 /*
00043  * Main entry score 
00044  * ----------------
00045  *
00046  */
00047 
00048 
00049 /*
00050  * Do all the score display
00051  */
00052 void
00053 gc_score_start (ScoreStyleList style, guint gx, guint gy, guint gmax)
00054 {
00055 
00056   currentStyle = style;
00057   x = gx;
00058   y = gy;
00059   max = gmax;
00060 
00061 
00062   switch(currentStyle) {
00063   case SCORESTYLE_NOTE :
00064     break;
00065   default:
00066     break;
00067   }
00068 }
00069 
00070 
00071 void
00072 gc_score_end()
00073 {
00074   if(boardRootItem!=NULL)
00075     gtk_object_destroy (GTK_OBJECT(boardRootItem));
00076   
00077   boardRootItem=NULL;
00078 }
00079 
00080 void
00081 gc_score_set(guint value)
00082 {
00083 
00084   if(boardRootItem!=NULL)
00085     gtk_object_destroy (GTK_OBJECT(boardRootItem));
00086 
00087   boardRootItem = GNOME_CANVAS_GROUP(
00088                                  gnome_canvas_item_new (
00089                                                      gnome_canvas_root(gc_board_get_current()->canvas),
00090                                                      gnome_canvas_group_get_type (),
00091                                                      "x", (double) x,
00092                                                      "y", (double) y,
00093                                                      NULL));
00094 
00095   switch(currentStyle) {
00096   case SCORESTYLE_NOTE :
00097     {
00098       gchar *tmp;
00099       GdkPixbuf *button_pixmap = NULL;
00100 
00101       button_pixmap = gc_skin_pixmap_load("button_large.png");
00102       gnome_canvas_item_new (boardRootItem,
00103                           gnome_canvas_pixbuf_get_type (),
00104                           "pixbuf",  button_pixmap,
00105                           "x",  (double) 0,
00106                           "y",  (double) -gdk_pixbuf_get_height(button_pixmap)/2,
00107                           NULL);
00108       gdk_pixbuf_unref(button_pixmap);
00109 
00110       tmp = g_strdup_printf("%d/%d", value, max);
00111       display_number(boardRootItem, gdk_pixbuf_get_width(button_pixmap)+10, 0, tmp);
00112       g_free(tmp);
00113     }
00114     break;
00115   default:
00116     break;
00117   }
00118 }
00119 
00120 /*-------------------------------------------------------------------------------*/
00121 /*-------------------------------------------------------------------------------*/
00122 /*-------------------------------------------------------------------------------*/
00123 /*-------------------------------------------------------------------------------*/
00124 
00125 
00126 #define NUMBERSWIDTH       110
00127 
00128 static void
00129 display_number(GnomeCanvasGroup *parent, 
00130               guint x,
00131               guint y, 
00132               char *operand_str)
00133 {
00134 
00135   x -= NUMBERSWIDTH;
00136 
00137   gnome_canvas_item_new (parent,
00138                       gnome_canvas_text_get_type (),
00139                       "text", operand_str,
00140                       "font", gc_skin_font_board_huge_bold,
00141                       "x", (double) x+2,
00142                       "y", (double) y+2,
00143                       "anchor", GTK_ANCHOR_CENTER,
00144                       "fill_color_rgba", 0x7a8699FF,
00145                       NULL);
00146   gnome_canvas_item_new (parent,
00147                       gnome_canvas_text_get_type (),
00148                       "text", operand_str,
00149                       "font", gc_skin_font_board_huge_bold,
00150                       "x", (double) x,
00151                       "y", (double) y,
00152                       "anchor", GTK_ANCHOR_CENTER,
00153                       "fill_color_rgba", 0xe5e532FF,
00154                       NULL);
00155 }