Back to index

gcompris  8.2.2
Defines | Functions | Variables
gcompris_confirm.c File Reference
#include <string.h>
#include "gcompris.h"

Go to the source code of this file.

Defines

#define BG_X   400
#define BG_Y   0
#define T_X   80
#define T_Y   24
#define T_W   620
#define T_H   30
#define T_Z_X   80
#define T_Z_Y   120
#define T_Z_W   620
#define T_Z_H   115
#define T_B_X   80
#define T_B_Y   250
#define T_B_W   620
#define T_B_H   192
#define T_B_X_INT   30

Functions

static void display_confirm (gchar *title, gchar *question_text, gchar *yes_text, gchar *no_text, ConfirmCallBack iscb)
static gint button_event (GnomeCanvasItem *item, GdkEvent *event, gchar *answer)
static void set_content (GnomeCanvasRichText *item_content, GnomeCanvasRichText *item_content_s, gchar *text)
void gc_confirm_box (gchar *title, gchar *question_text, gchar *yes_text, gchar *no_text, ConfirmCallBack iscb)
void gc_confirm_box_stop ()

Variables

static GnomeCanvasItem * richtext_s
 A confirmation popup for gcompris.
static GnomeCanvasItem * richtext
static gboolean confirm_displayed = FALSE
static GnomeCanvasItem * rootitem = NULL
static GnomeCanvasItem * no_button = NULL
static GnomeCanvasItem * yes_button = NULL
static GnomeCanvasItem * yes_stick = NULL
static GnomeCanvasItem * no_cross = NULL
static ConfirmCallBack confirmCallBack = NULL
static gdouble bg_x
static gdouble bg_y
static gdouble titre_x
static gdouble titre_w
static gdouble titre_y
static gdouble titre_h
static gdouble text_zone_x
static gdouble text_zone_w
static gdouble text_zone_y
static gdouble text_zone_h
static gdouble button_x
static gdouble button_w
static gdouble button_y
static gdouble button_h
static gdouble button_x_int

Define Documentation

#define BG_X   400

Definition at line 76 of file gcompris_confirm.c.

#define BG_Y   0

Definition at line 77 of file gcompris_confirm.c.

#define T_B_H   192

Definition at line 95 of file gcompris_confirm.c.

#define T_B_W   620

Definition at line 94 of file gcompris_confirm.c.

#define T_B_X   80

Definition at line 92 of file gcompris_confirm.c.

#define T_B_X_INT   30

Definition at line 96 of file gcompris_confirm.c.

#define T_B_Y   250

Definition at line 93 of file gcompris_confirm.c.

#define T_H   30

Definition at line 83 of file gcompris_confirm.c.

#define T_W   620

Definition at line 82 of file gcompris_confirm.c.

#define T_X   80

Definition at line 80 of file gcompris_confirm.c.

#define T_Y   24

Definition at line 81 of file gcompris_confirm.c.

#define T_Z_H   115

Definition at line 89 of file gcompris_confirm.c.

#define T_Z_W   620

Definition at line 88 of file gcompris_confirm.c.

#define T_Z_X   80

Definition at line 86 of file gcompris_confirm.c.

#define T_Z_Y   120

Definition at line 87 of file gcompris_confirm.c.


Function Documentation

static gint button_event ( GnomeCanvasItem *  item,
GdkEvent *  event,
gchar *  answer 
) [static]

Definition at line 462 of file gcompris_confirm.c.

{
  if (event->type != GDK_BUTTON_PRESS)
    return FALSE;

  /* Callback with the proper params */
  if (confirmCallBack){
    if (strcmp(answer, "/no/")==0)
      confirmCallBack(FALSE);
    else
      confirmCallBack(TRUE);
  }
  gc_confirm_box_stop();

  return TRUE;
  
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void display_confirm ( gchar *  title,
gchar *  question_text,
gchar *  yes_text,
gchar *  no_text,
ConfirmCallBack  iscb 
) [static]

Definition at line 162 of file gcompris_confirm.c.

                                    {

  GnomeCanvasItem  *item, *item2;
  GdkPixbuf      *pixmap = NULL;
  GdkPixbuf      *pixmap_cross = NULL;
  GdkPixbuf      *pixmap_stick = NULL;
  gint            y_start = 0;
  gint            x_start = 0;

  if(rootitem)
    return;

  bg_x = BG_X;
  bg_y = BG_Y;

  titre_x = T_X;
  titre_w = T_W;
  titre_y = T_Y;;
  titre_h = T_H;


  text_zone_x = T_Z_X;
  text_zone_w = T_Z_W;
  text_zone_y = T_Z_Y;
  text_zone_h = T_Z_H;


  button_x = T_B_X;
  button_w = T_B_W;
  button_y = T_B_Y;
  button_h = T_B_Y;
  button_x_int = T_B_X_INT;

  gc_bar_hide(TRUE);

  gc_board_pause(TRUE);

  confirmCallBack=iscb;

  rootitem = \
    gnome_canvas_item_new (gnome_canvas_root(gc_get_canvas()),
                        gnome_canvas_group_get_type (),
                        "x", (double)0,
                        "y", (double)0,
                        NULL);

  pixmap = gc_skin_pixmap_load("help_bg.png");
  y_start = (BOARDHEIGHT - gdk_pixbuf_get_height(pixmap))/2;
  if (y_start < 0)
    y_start = 0;
  x_start = (BOARDWIDTH)/2;
  item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                            gnome_canvas_pixbuf_get_type (),
                            "pixbuf", pixmap, 
                            "x", (double) x_start,
                            "y", (double) y_start,
                            "anchor", GTK_ANCHOR_NORTH,
                            NULL);

  gdk_pixbuf_unref(pixmap);

  /* Title */
  gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                      gnome_canvas_text_get_type (),
                      "text", title,
                      "x", (gdouble) titre_x + titre_w/2 + 1.0,
                      "y", (gdouble) titre_y + titre_h/2 + 1.0,
                      "font", gc_skin_font_title,
                      "anchor", GTK_ANCHOR_CENTER,
                      "fill_color_rgba",  gc_skin_color_shadow,
                      NULL);

  gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                      gnome_canvas_text_get_type (),
                      "text", title,
                      "x", (gdouble) titre_x + titre_w/2,
                      "y", (gdouble) titre_y + titre_h/2,
                      "font", gc_skin_font_title,
                      "anchor", GTK_ANCHOR_CENTER,
                      "fill_color_rgba",  gc_skin_color_title,
                      NULL);

  richtext_s = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                                 gnome_canvas_rich_text_get_type (),
                                 "x", (double) text_zone_x + 1.0,
                                 "y", (double)  text_zone_y + 1.0,
                                 "width",  text_zone_w,
                                 "height", text_zone_h,
                                 "anchor", GTK_ANCHOR_NW,
                                 "justification", GTK_JUSTIFY_CENTER,
                                 "grow_height", FALSE,
                                 "cursor_visible", FALSE,
                                 "cursor_blink", FALSE,
                                 "editable", FALSE,
                                 NULL);


  richtext = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                                 gnome_canvas_rich_text_get_type (),
                                 "x", (double) text_zone_x ,
                                 "y", (double)  text_zone_y,
                                 "width",  text_zone_w,
                                 "height", text_zone_h,
                                 "anchor", GTK_ANCHOR_NW,
                                 "justification", GTK_JUSTIFY_CENTER,
                                 "grow_height", FALSE,
                                 "cursor_visible", FALSE,
                                 "cursor_blink", FALSE,
                                 "editable", FALSE,
                                 NULL);

  set_content (GNOME_CANVAS_RICH_TEXT(richtext), 
              GNOME_CANVAS_RICH_TEXT(richtext_s), 
              question_text);
        
  
  /*
   * Buttons
   * -------
   */

  pixmap = gc_skin_pixmap_load("button_large.png");
  pixmap_stick = gc_skin_pixmap_load("button_checked.png");
  pixmap_cross = gc_skin_pixmap_load("bad.png");

  // CANCEL
  no_button = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                                 gnome_canvas_pixbuf_get_type (),
                                 "pixbuf", pixmap, 
                                 "x", (double) button_x ,
                                 "y", (double) button_y + 2*button_h/3,
                                 "anchor", GTK_ANCHOR_WEST,
                                 NULL);

  //gdk_pixbuf_unref(pixmap);

  gtk_signal_connect(GTK_OBJECT(no_button), "event",
                   (GtkSignalFunc) button_event,
                   "/no/");

  gtk_signal_connect(GTK_OBJECT(no_button), "event",
                   (GtkSignalFunc) gc_item_focus_event,
                   NULL);

  // CANCEL CROSS
  no_cross = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                                gnome_canvas_pixbuf_get_type (),
                                "pixbuf", pixmap_cross, 
                                "x", (double) button_x  + gdk_pixbuf_get_width(pixmap)/2,
                                "y", (double) button_y + 2*button_h/3,
                                "anchor", GTK_ANCHOR_CENTER,
                                NULL);

  gdk_pixbuf_unref(pixmap_cross);

  gtk_signal_connect(GTK_OBJECT(no_cross), "event",
                   (GtkSignalFunc) button_event,
                   "/no/");
  gtk_signal_connect(GTK_OBJECT(no_cross), "event",
                   (GtkSignalFunc) gc_item_focus_event,
                   NULL);


  gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                      gnome_canvas_text_get_type (),
                      "text", no_text,
                      "font", gc_skin_font_subtitle,
                      "x", (double)  button_x + gdk_pixbuf_get_width(pixmap) + button_x_int ,
                      "y", (double)  button_y + 2*button_h/3,
                      "anchor", GTK_ANCHOR_WEST,
                      "fill_color_rgba", gc_skin_get_color("gcompris/helpfg"),
                      NULL);

  // OK
  yes_button = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                                  gnome_canvas_pixbuf_get_type (),
                                  "pixbuf", pixmap, 
                                  "x", (double) button_x ,
                                  "y", (double) button_y + button_h/3,
                                  "anchor", GTK_ANCHOR_WEST,
                                  NULL);
  
  gdk_pixbuf_unref(pixmap);
  
  gtk_signal_connect(GTK_OBJECT(yes_button), "event",
                   (GtkSignalFunc) button_event,
                   "/yes/");

  gtk_signal_connect(GTK_OBJECT(yes_button), "event",
                   (GtkSignalFunc) gc_item_focus_event,
                   NULL);

  // OK stick
  yes_stick = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                                 gnome_canvas_pixbuf_get_type (),
                                 "pixbuf", pixmap_stick, 
                                 "x", (double) button_x + gdk_pixbuf_get_width(pixmap)/2,
                                 "y", (double) button_y + button_h/3,
                                 "anchor", GTK_ANCHOR_CENTER,
                                 NULL);

  gdk_pixbuf_unref(pixmap_stick);

  gtk_signal_connect(GTK_OBJECT(yes_stick), "event",
                   (GtkSignalFunc) button_event,
                   "/yes/");
  gtk_signal_connect(GTK_OBJECT(yes_stick), "event",
                   (GtkSignalFunc) gc_item_focus_event,
                   NULL);


  item2 = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
                             gnome_canvas_text_get_type (),
                             "text", yes_text,
                             "font", gc_skin_font_subtitle,
                             "x", (double)  button_x + gdk_pixbuf_get_width(pixmap) + button_x_int ,
                             "y", (double)  button_y + button_h/3,
                             "anchor", GTK_ANCHOR_WEST,
                             "fill_color_rgba", gc_skin_get_color("gcompris/helpfg"),
                             NULL);

  confirm_displayed = TRUE;

}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_confirm_box ( gchar *  title,
gchar *  question_text,
gchar *  yes_text,
gchar *  no_text,
ConfirmCallBack  iscb 
)

Definition at line 110 of file gcompris_confirm.c.

{
  display_confirm(title, 
                question_text, 
                yes_text,
                no_text,
                iscb);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_confirm_box_stop ( void  )

Definition at line 128 of file gcompris_confirm.c.

{
  GcomprisBoard *gcomprisBoard = gc_board_get_current();

  // Destroy the box
  /* FIXME: Crashes randomly */
  if(rootitem!=NULL)
    {
      /* WORKAROUND: There is a bug in the richtex item and we need to remove it first */
      while (g_idle_remove_by_data (richtext));
      gtk_object_destroy (GTK_OBJECT(richtext));
      while (g_idle_remove_by_data (richtext_s));
      gtk_object_destroy (GTK_OBJECT(richtext_s));
      gtk_object_destroy(GTK_OBJECT(rootitem));
    }

  rootitem = NULL;     

  if(gcomprisBoard!=NULL && confirm_displayed)
    gc_board_pause(FALSE);

  gc_bar_hide(FALSE);
  confirm_displayed = FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_content ( GnomeCanvasRichText *  item_content,
GnomeCanvasRichText *  item_content_s,
gchar *  text 
) [static]

Definition at line 393 of file gcompris_confirm.c.

                        {

  GtkTextIter    iter_start, iter_end;
  GtkTextBuffer *buffer;
  GtkTextTag    *txt_tag;
  gboolean success; 
  gchar *color_string;
  GdkColor *color_s = (GdkColor *)malloc(sizeof(GdkColor));
  GdkColor *color   = (GdkColor *)malloc(sizeof(GdkColor));

  /*
   * Set the new text in the 2 items
   */
  gnome_canvas_item_set(GNOME_CANVAS_ITEM(item_content),
                     "text", text,
                     NULL);

  gnome_canvas_item_set(GNOME_CANVAS_ITEM(item_content_s),
                     "text", text,
                     NULL);

  /*
   * Set the shadow
   */

  color_string = g_strdup_printf("#%x", gc_skin_color_shadow >> 8);
  gdk_color_parse(color_string, color_s);
  g_free(color_string);
  success = gdk_colormap_alloc_color(gdk_colormap_get_system(), 
                                 color_s,
                                 FALSE, TRUE); 

  buffer  = gnome_canvas_rich_text_get_buffer(GNOME_CANVAS_RICH_TEXT(item_content_s));
  txt_tag = gtk_text_buffer_create_tag(buffer, NULL, 
                                   "foreground-gdk", color_s,
                                   "font",       gc_skin_font_board_medium,
                                   NULL);
  gtk_text_buffer_get_end_iter(buffer, &iter_end);
  gtk_text_buffer_get_start_iter(buffer, &iter_start);
  gtk_text_buffer_apply_tag(buffer, txt_tag, &iter_start, &iter_end);


  /* 
   * Set the text
   */
  color_string = g_strdup_printf("#%x", gc_skin_get_color("gcompris/helpunselect") >> 8);
  gdk_color_parse(color_string, color);
  g_free(color_string);
  success = gdk_colormap_alloc_color(gdk_colormap_get_system(), 
                                 color,
                                 FALSE, TRUE); 

  buffer  = gnome_canvas_rich_text_get_buffer(GNOME_CANVAS_RICH_TEXT(item_content));
  txt_tag = gtk_text_buffer_create_tag(buffer, NULL, 
                                   "foreground-gdk", color,
                                   "font",        gc_skin_font_board_medium,
                                   NULL);
  gtk_text_buffer_get_end_iter(buffer, &iter_end);
  gtk_text_buffer_get_start_iter(buffer, &iter_start);
  gtk_text_buffer_apply_tag(buffer, txt_tag, &iter_start, &iter_end);

  g_free(color);
  g_free(color_s);

}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

gdouble bg_x [static]

Definition at line 54 of file gcompris_confirm.c.

gdouble bg_y [static]

Definition at line 55 of file gcompris_confirm.c.

gdouble button_h [static]

Definition at line 72 of file gcompris_confirm.c.

gdouble button_w [static]

Definition at line 70 of file gcompris_confirm.c.

gdouble button_x [static]

Definition at line 69 of file gcompris_confirm.c.

gdouble button_x_int [static]

Definition at line 73 of file gcompris_confirm.c.

gdouble button_y [static]

Definition at line 71 of file gcompris_confirm.c.

gboolean confirm_displayed = FALSE [static]

Definition at line 44 of file gcompris_confirm.c.

Definition at line 52 of file gcompris_confirm.c.

GnomeCanvasItem* no_button = NULL [static]

Definition at line 47 of file gcompris_confirm.c.

GnomeCanvasItem* no_cross = NULL [static]

Definition at line 50 of file gcompris_confirm.c.

GnomeCanvasItem * richtext [static]

Definition at line 29 of file gcompris_confirm.c.

GnomeCanvasItem* richtext_s [static]

A confirmation popup for gcompris.

Definition at line 29 of file gcompris_confirm.c.

GnomeCanvasItem* rootitem = NULL [static]

Definition at line 46 of file gcompris_confirm.c.

gdouble text_zone_h [static]

Definition at line 66 of file gcompris_confirm.c.

gdouble text_zone_w [static]

Definition at line 64 of file gcompris_confirm.c.

gdouble text_zone_x [static]

Definition at line 63 of file gcompris_confirm.c.

gdouble text_zone_y [static]

Definition at line 65 of file gcompris_confirm.c.

gdouble titre_h [static]

Definition at line 60 of file gcompris_confirm.c.

gdouble titre_w [static]

Definition at line 58 of file gcompris_confirm.c.

gdouble titre_x [static]

Definition at line 57 of file gcompris_confirm.c.

gdouble titre_y [static]

Definition at line 59 of file gcompris_confirm.c.

GnomeCanvasItem* yes_button = NULL [static]

Definition at line 48 of file gcompris_confirm.c.

GnomeCanvasItem* yes_stick = NULL [static]

Definition at line 49 of file gcompris_confirm.c.