Back to index

gcompris  8.2.2
Classes | Defines | Typedefs | Enumerations | Functions
money_widget.h File Reference
#include <gtk/gtk.h>
#include "gcompris/gcompris.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _Money_WidgetClass
struct  _Money_Widget

Defines

#define TYPE_MONEY_WIDGET   (money_widget_get_type ())
#define MONEY_WIDGET(obj)   GTK_CHECK_CAST (obj, TYPE_MONEY_WIDGET, Money_Widget)
#define MONEY_WIDGET_CLASS(klass)   GTK_CHECK_CLASS_CAST (klass, TYPE_MONEY_WIDGET, Money_WidgetClass)
#define IS_MONEY_WIDGET(obj)   GTK_CHECK_TYPE (obj, TYPE_MONEY_WIDGET)

Typedefs

typedef struct _Money_Widget
typedef struct _Money_WidgetClass
typedef struct _Money_WidgetPrivate

Enumerations

enum  MoneyEuroType {
  MONEY_EURO_COIN_1C, MONEY_EURO_COIN_2C, MONEY_EURO_COIN_5C, MONEY_EURO_COIN_10C,
  MONEY_EURO_COIN_20C, MONEY_EURO_COIN_50C, MONEY_EURO_COIN_1E, MONEY_EURO_COIN_2E,
  MONEY_EURO_PAPER_5E, MONEY_EURO_PAPER_10E, MONEY_EURO_PAPER_20E, MONEY_EURO_PAPER_50E
}

Functions

GtkType money_widget_get_type (void)
GtkObject * money_widget_new (void)
Money_Widget * money_widget_copy (Money_Widget *moneyWidget)
void money_widget_set_target (Money_Widget *moneyWidget, Money_Widget *targetWidget)
void money_widget_set_position (Money_Widget *moneyWidget, GnomeCanvasGroup *rootItem, double x1, double y1, double x2, double y2, guint colomns, guint lines, gboolean display_total)
void money_widget_add (Money_Widget *moneyWidget, MoneyEuroType value)
void money_widget_remove (Money_Widget *moneyWidget, MoneyEuroType value)
double money_widget_get_total (Money_Widget *moneyWidget)

Class Documentation

struct _Money_WidgetClass

Definition at line 45 of file money_widget.h.

Class Members
GtkObjectClass parent_class
struct _Money_Widget

Definition at line 49 of file money_widget.h.

Class Members
GtkObject object
Money_WidgetPrivate * priv

Define Documentation

#define IS_MONEY_WIDGET (   obj)    GTK_CHECK_TYPE (obj, TYPE_MONEY_WIDGET)

Definition at line 39 of file money_widget.h.

#define MONEY_WIDGET (   obj)    GTK_CHECK_CAST (obj, TYPE_MONEY_WIDGET, Money_Widget)

Definition at line 37 of file money_widget.h.

#define MONEY_WIDGET_CLASS (   klass)    GTK_CHECK_CLASS_CAST (klass, TYPE_MONEY_WIDGET, Money_WidgetClass)

Definition at line 38 of file money_widget.h.

Definition at line 36 of file money_widget.h.


Typedef Documentation

typedef struct _Money_Widget

Definition at line 41 of file money_widget.h.

typedef struct _Money_WidgetClass

Definition at line 42 of file money_widget.h.

typedef struct _Money_WidgetPrivate

Definition at line 43 of file money_widget.h.


Enumeration Type Documentation

Enumerator:
MONEY_EURO_COIN_1C 
MONEY_EURO_COIN_2C 
MONEY_EURO_COIN_5C 
MONEY_EURO_COIN_10C 
MONEY_EURO_COIN_20C 
MONEY_EURO_COIN_50C 
MONEY_EURO_COIN_1E 
MONEY_EURO_COIN_2E 
MONEY_EURO_PAPER_5E 
MONEY_EURO_PAPER_10E 
MONEY_EURO_PAPER_20E 
MONEY_EURO_PAPER_50E 

Definition at line 55 of file money_widget.h.


Function Documentation

void money_widget_add ( Money_Widget *  moneyWidget,
MoneyEuroType  value 
)

Definition at line 239 of file money_widget.c.

{
  GnomeCanvasItem *item   = NULL;
  GdkPixbuf       *pixmap = NULL;
  double         xratio, yratio, ratio;
  double         block_width, block_height;
  MoneyItem     *moneyitem;
  guint                 i, length;

  g_return_if_fail (moneyWidget != NULL);

  /* Search for an hidden item with the same value */
  length = g_list_length(moneyWidget->priv->moneyItemList);
  for(i=0; i<length; i++)
    {
      moneyitem = (MoneyItem *)g_list_nth_data(moneyWidget->priv->moneyItemList, i);

      if(moneyitem && !moneyitem->inPocket && moneyitem->value == value)
       {
         gnome_canvas_item_show(moneyitem->item);
         moneyitem->inPocket = TRUE;
         moneyWidget->priv->total += euroList[value].value;
         money_display_total(moneyWidget);
         return;
       }
    }
  
  /* There is no already suitable item create, create a new one */

  if(moneyWidget->priv->next_spot > moneyWidget->priv->columns * moneyWidget->priv->lines)
    g_message("More money items requested than the pocket size\n");

  block_width  = (moneyWidget->priv->x2 - moneyWidget->priv->x1) / moneyWidget->priv->columns;
  block_height = (moneyWidget->priv->y2 - moneyWidget->priv->y1) / moneyWidget->priv->lines;

  pixmap = gc_pixmap_load((gchar *)euroList[value].image);

  xratio =  block_width  / (gdk_pixbuf_get_width (pixmap) + BORDER_GAP);
  yratio =  block_height / (gdk_pixbuf_get_height(pixmap) + BORDER_GAP);
  ratio = yratio = MIN(xratio, yratio);

  item =  gnome_canvas_item_new ( moneyWidget->priv->rootItem,
                              gnome_canvas_pixbuf_get_type (),
                              "pixbuf", pixmap,
                              "x", (double) moneyWidget->priv->x1 + 
                              (moneyWidget->priv->next_spot % moneyWidget->priv->columns) * block_width
                              +  block_width/2 - (gdk_pixbuf_get_width(pixmap) * ratio)/2,
                              "y", (double)moneyWidget->priv->y1 +
                              (moneyWidget->priv->next_spot / moneyWidget->priv->columns)
                              * block_height
                              + block_height/2 - (gdk_pixbuf_get_height(pixmap) * ratio)/2,
                              "width",  (double) gdk_pixbuf_get_width(pixmap)  * ratio,
                              "height", (double) gdk_pixbuf_get_height(pixmap) * ratio,
                              "width_set", TRUE, 
                              "height_set", TRUE,
                              NULL);

  moneyitem = g_malloc(sizeof(MoneyItem));
  moneyitem->moneyWidget = moneyWidget;
  moneyitem->item   = item;
  moneyitem->value  = value;
  moneyitem->inPocket = TRUE;

  moneyWidget->priv->moneyItemList = g_list_append (moneyWidget->priv->moneyItemList,
                                              moneyitem);

  gtk_signal_connect(GTK_OBJECT(item), "event", (GtkSignalFunc) item_event, moneyitem);

  gdk_pixbuf_unref(pixmap);

  moneyWidget->priv->next_spot++;

  moneyWidget->priv->total += euroList[value].value;

  money_display_total(moneyWidget);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Money_Widget* money_widget_copy ( Money_Widget *  moneyWidget)

Definition at line 159 of file money_widget.c.

{
       Money_Widget *cpPos;

       cpPos = MONEY_WIDGET (money_widget_new ());

       memcpy (cpPos->priv, pos->priv, sizeof (Money_WidgetPrivate));

       return cpPos;
}

Here is the call graph for this function:

double money_widget_get_total ( Money_Widget *  moneyWidget)

Definition at line 327 of file money_widget.c.

{
  if(moneyWidget == NULL)
    return 0;

  return moneyWidget->priv->total;
}

Here is the caller graph for this function:

GtkType money_widget_get_type ( void  )

Definition at line 88 of file money_widget.c.

{
       static guint money_widget_type = 0;

       if (!money_widget_type) {
              GtkTypeInfo money_widget_info = {
                     "Money_Widget",
                     sizeof (Money_Widget),
                     sizeof (Money_WidgetClass),
                     (GtkClassInitFunc) class_init,
                     (GtkObjectInitFunc) init,
                     (gpointer) NULL,
                     (gpointer) NULL,
                     (GtkClassInitFunc) NULL
              };
              money_widget_type = gtk_type_unique (gtk_object_get_type (),
                                           &money_widget_info);
       }

       return money_widget_type;
}

Here is the call graph for this function:

Here is the caller graph for this function:

GtkObject* money_widget_new ( void  )

Definition at line 153 of file money_widget.c.

{
       return GTK_OBJECT (gtk_type_new (money_widget_get_type ()));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void money_widget_remove ( Money_Widget *  moneyWidget,
MoneyEuroType  value 
)

Definition at line 317 of file money_widget.c.

{
  g_return_if_fail (moneyWidget != NULL);

  moneyWidget->priv->total -= euroList[value].value;

  money_display_total(moneyWidget);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void money_widget_set_position ( Money_Widget *  moneyWidget,
GnomeCanvasGroup *  rootItem,
double  x1,
double  y1,
double  x2,
double  y2,
guint  colomns,
guint  lines,
gboolean  display_total 
)

Definition at line 178 of file money_widget.c.

{
  g_return_if_fail (moneyWidget != NULL);
  
  moneyWidget->priv->rootItem = rootItem;
  moneyWidget->priv->x1 = x1;
  moneyWidget->priv->y1 = y1;
  moneyWidget->priv->x2 = x2;
  moneyWidget->priv->y2 = y2;
  moneyWidget->priv->columns = columns;
  moneyWidget->priv->lines = lines;
  moneyWidget->priv->next_spot = 0;
  moneyWidget->priv->display_total = display_total;

  /* Uncomment to display the limits
    gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootItem),
                      gnome_canvas_rect_get_type (),
                      "x1", (double) x1,
                      "y1", (double) y1,
                      "x2", (double) x2,
                      "y2", (double) y2,
                      "outline_color", "red",
                      "width_pixels", 2,
                      NULL);
  */

  moneyWidget->priv->item_total =  gnome_canvas_item_new(rootItem,
                                                 gnome_canvas_text_get_type (),
                                                 "text", "",
                                                 "font", gc_skin_font_board_big,
                                                 "x", (double) x1+(x2-x1)/2,
                                                 "y", (double) y2 + 10,
                                                 "anchor", GTK_ANCHOR_CENTER,
                                                 "fill_color", "white",
                                                 NULL);

}

Here is the caller graph for this function:

void money_widget_set_target ( Money_Widget *  moneyWidget,
Money_Widget *  targetWidget 
)

Definition at line 171 of file money_widget.c.

{
  moneyWidget->priv->targetWidget = targetWidget;
}

Here is the caller graph for this function: