[gcompris] Added a font selector in the config dialog box.
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris] Added a font selector in the config dialog box.
- Date: Sat, 16 Nov 2013 22:16:31 +0000 (UTC)
commit efe75d9c8bd5194cbb35e8e8050ad4ab6e57f3df
Author: Bruno Coudoin <bcoudoin gcompris net>
Date: Sat Nov 16 23:13:30 2013 +0100
Added a font selector in the config dialog box.
This feature replaces the skin selector.
Removed the skin gartoon as it is useless now.
boards/skins/README | 8 -
boards/skins/babytoy/skin.xml | 31 +-
boards/skins/gartoon/README | 2 -
boards/skins/gartoon/bonus/README | 4 -
boards/skins/gartoon/bonus/flower_bad.png | Bin 49929 -> 0 bytes
boards/skins/gartoon/bonus/flower_good.png | Bin 40561 -> 0 bytes
boards/skins/gartoon/bonus/gnu_bad.png | Bin 37258 -> 0 bytes
boards/skins/gartoon/bonus/gnu_good.png | Bin 31016 -> 0 bytes
boards/skins/gartoon/bonus/lion_bad.png | Bin 23309 -> 0 bytes
boards/skins/gartoon/bonus/lion_good.png | Bin 24514 -> 0 bytes
boards/skins/gartoon/bonus/note_bad.png | Bin 5663 -> 0 bytes
boards/skins/gartoon/bonus/note_good.png | Bin 5857 -> 0 bytes
boards/skins/gartoon/bonus/smiley_bad.png | Bin 51623 -> 0 bytes
boards/skins/gartoon/bonus/smiley_good.png | Bin 50124 -> 0 bytes
boards/skins/gartoon/bonus/tux_bad.png | Bin 30837 -> 0 bytes
boards/skins/gartoon/bonus/tux_good.png | Bin 36012 -> 0 bytes
boards/skins/gartoon/cursors/circle.png | Bin 2887 -> 0 bytes
boards/skins/gartoon/cursors/default.png | Bin 1958 -> 0 bytes
boards/skins/gartoon/cursors/del.png | Bin 4553 -> 0 bytes
boards/skins/gartoon/cursors/fill.png | Bin 2447 -> 0 bytes
boards/skins/gartoon/cursors/fillcircle.png | Bin 2671 -> 0 bytes
boards/skins/gartoon/cursors/fillrect.png | Bin 2537 -> 0 bytes
boards/skins/gartoon/cursors/line.png | Bin 1452 -> 0 bytes
boards/skins/gartoon/cursors/rect.png | Bin 2252 -> 0 bytes
boards/skins/gartoon/cursors/select.png | Bin 2181 -> 0 bytes
boards/skins/gartoon/skin.svg | 4300 ---------------------------
boards/skins/gartoon/skin.xml | 50 -
boards/skins/gartoon/timers/README | 1 -
boards/skins/gartoon/timers/clock1.png | Bin 13438 -> 0 bytes
boards/skins/gartoon/timers/clock10.png | Bin 13705 -> 0 bytes
boards/skins/gartoon/timers/clock2.png | Bin 13652 -> 0 bytes
boards/skins/gartoon/timers/clock3.png | Bin 13811 -> 0 bytes
boards/skins/gartoon/timers/clock4.png | Bin 13461 -> 0 bytes
boards/skins/gartoon/timers/clock5.png | Bin 13537 -> 0 bytes
boards/skins/gartoon/timers/clock6.png | Bin 13235 -> 0 bytes
boards/skins/gartoon/timers/clock7.png | Bin 13802 -> 0 bytes
boards/skins/gartoon/timers/clock8.png | Bin 13675 -> 0 bytes
boards/skins/gartoon/timers/clock9.png | Bin 13784 -> 0 bytes
boards/skins/gartoon/timers/sablier.gif | Bin 140347 -> 0 bytes
boards/skins/gartoon/timers/sablier1.png | Bin 16711 -> 0 bytes
boards/skins/gartoon/timers/sablier10.png | Bin 17188 -> 0 bytes
boards/skins/gartoon/timers/sablier2.png | Bin 16822 -> 0 bytes
boards/skins/gartoon/timers/sablier3.png | Bin 16884 -> 0 bytes
boards/skins/gartoon/timers/sablier4.png | Bin 16858 -> 0 bytes
boards/skins/gartoon/timers/sablier5.png | Bin 16929 -> 0 bytes
boards/skins/gartoon/timers/sablier6.png | Bin 17162 -> 0 bytes
boards/skins/gartoon/timers/sablier7.png | Bin 17135 -> 0 bytes
boards/skins/gartoon/timers/sablier8.png | Bin 17133 -> 0 bytes
boards/skins/gartoon/timers/sablier9.png | Bin 17093 -> 0 bytes
boards/skins/gartoon/timers/sea.png | Bin 51067 -> 0 bytes
boards/skins/gartoon/timers/tuxballoon.png | Bin 13417 -> 0 bytes
src/gcompris/config.c | 163 +-
src/gcompris/gcompris.h | 1 -
src/gcompris/properties.c | 12 +-
src/gcompris/properties.h | 1 +
src/gcompris/skin.c | 50 +-
src/gcompris/skin.h | 2 +-
57 files changed, 154 insertions(+), 4471 deletions(-)
---
diff --git a/boards/skins/babytoy/skin.xml b/boards/skins/babytoy/skin.xml
index a7b0cdd..87b17f6 100644
--- a/boards/skins/babytoy/skin.xml
+++ b/boards/skins/babytoy/skin.xml
@@ -23,24 +23,23 @@
<number id="gcompris/fileselectdiry" value="80"/>
<!-- Defines the main gcompris fonts -->
- <font id="gcompris/fontface" name="sans"/>
- <font id="gcompris/title" name="sans 20"/>
- <font id="gcompris/subtitle" name="sans 16"/>
- <font id="gcompris/content" name="sans 12"/>
- <font id="gcompris/tiny" name="sans 10"/>
+ <font id="gcompris/title" name="20"/>
+ <font id="gcompris/subtitle" name="16"/>
+ <font id="gcompris/content" name="12"/>
+ <font id="gcompris/tiny" name="10"/>
<!-- Defines the gcompris boards fonts -->
- <font id="gcompris/board/tiny" name="sans 10"/>
- <font id="gcompris/board/small" name="sans 12"/>
- <font id="gcompris/board/medium" name="sans 14" />
- <font id="gcompris/board/big" name="sans 18" />
- <font id="gcompris/board/big bold" name="sans bold 17"/>
- <font id="gcompris/board/fixed" name="sans 12"/>
- <font id="gcompris/board/title" name="sans 20"/>
- <font id="gcompris/board/title bold" name="sans bold 21"/>
- <font id="gcompris/board/huge" name="sans 28"/>
- <font id="gcompris/board/huge bold" name="sans bold 29"/>
- <font id="gcompris/board/gigantic" name="sans 78"/>
+ <font id="gcompris/board/tiny" name="10"/>
+ <font id="gcompris/board/small" name="12"/>
+ <font id="gcompris/board/medium" name="14" />
+ <font id="gcompris/board/big" name="18" />
+ <font id="gcompris/board/big bold" name="bold 17"/>
+ <font id="gcompris/board/fixed" name="12"/>
+ <font id="gcompris/board/title" name="20"/>
+ <font id="gcompris/board/title bold" name="bold 21"/>
+ <font id="gcompris/board/huge" name="28"/>
+ <font id="gcompris/board/huge bold" name="bold 29"/>
+ <font id="gcompris/board/gigantic" name="78"/>
<color id="menu/text" rgba="0x000000FF"/>
<color id="menu/description_bg_color" rgba="0xe8e7e2CCL"/>
diff --git a/src/gcompris/config.c b/src/gcompris/config.c
index fef3083..086da66 100644
--- a/src/gcompris/config.c
+++ b/src/gcompris/config.c
@@ -30,15 +30,16 @@
static GooCanvasItem *rootitem = NULL;
static GooCanvasItem *item_locale_text = NULL;
static GooCanvasItem *item_timer_text = NULL;
-static GooCanvasItem *item_skin_text = NULL;
+static GooCanvasItem *item_font_text = NULL;
static GooCanvasItem *item_filter_text = NULL;
static gchar *pixmap_checked = NULL;
static gchar *pixmap_unchecked = NULL;
static guint pixmap_width;
static gchar *current_locale = NULL;
-static GList *skinlist = NULL;
-static guint skin_index;
+static GList *fontlist = NULL;
+static guint font_index;
+static guint current_font_index;
static GooCanvasGroup *stars_group = NULL;
static double stars_group_x;
@@ -387,57 +388,50 @@ gc_config_start ()
"fill-color-rgba", gc_skin_color_content,
NULL);
- // Skin
+ // Font
+ y_start += Y_GAP;
{
- const gchar *one_dirent;
- guint i;
- GDir *dir;
- gchar *skin_dir;
- gchar *first_skin_name;
-
- /* Load the Pixpmaps directory file names */
- skin_dir = g_strconcat(properties->package_data_dir, "/skins", NULL);
- dir = g_dir_open(skin_dir, 0, NULL);
-
- if (!dir)
- g_warning (_("Couldn't open skin dir: %s"), skin_dir);
-
- /* Fill up the skin list */
- while((one_dirent = g_dir_read_name(dir)) != NULL) {
-
- if (one_dirent[0] != '.') {
- gchar *filename;
- /* Only directory here are skins */
- filename = g_strdup_printf("%s/%s", properties->package_skin_dir, one_dirent);
-
- if (g_file_test ((filename), G_FILE_TEST_IS_DIR)) {
- gchar *skin_name = g_strdup_printf("%s", one_dirent);
- skinlist = g_list_append (skinlist, skin_name);
- }
- g_free(filename);
- }
- }
- g_dir_close(dir);
-
- /* Find the current skin index */
- skin_index = 0;
- for(i=0; i<g_list_length(skinlist); i++)
- if(!strcmp((char *)g_list_nth_data(skinlist, i), properties->skin))
- skin_index = i;
-
- y_start += Y_GAP;
-
- /* Should not happen. It the user found the config, there should be a skin */
- if(g_list_length(skinlist) > 0) {
- g_warning("No skin found in %s\n", skin_dir);
- display_previous_next(x_start, y_start, "skin_previous", "skin_next");
- first_skin_name = g_strdup_printf(_("Skin : %s"), (char *)g_list_nth_data(skinlist, skin_index));
- } else {
- first_skin_name = g_strdup(_("SKINS NOT FOUND"));
+ int i;
+ PangoFontFamily ** families;
+ int n_families;
+ PangoFontMap * fontmap;
+ const gchar *current_familly_name = NULL;
+
+ fontmap = pango_cairo_font_map_get_default();
+ pango_font_map_list_families (fontmap, & families, & n_families);
+ for (i = 0; i < n_families; i++) {
+ PangoFontFamily * family = families[i];
+ const gchar * family_name;
+ family_name = pango_font_family_get_name (family);
+ fontlist = g_list_insert_sorted (fontlist, (gpointer)family_name,
+ (GCompareFunc)strcmp);
+ if(!strcmp(properties->fontface, family_name))
+ current_familly_name = family_name;
}
+ g_free (families);
+
+ current_font_index = font_index = g_list_index(fontlist, current_familly_name);
+ display_previous_next(x_start, y_start, "font_previous", "font_next");
- item_skin_text = goo_canvas_text_new (rootitem,
- first_skin_name,
+ /* A repeat icon to reset the selection */
+ item = goo_canvas_svg_new (rootitem,
+ gc_skin_rsvg_get(),
+ "svg-id", "#REPEAT",
+ NULL);
+ goo_canvas_item_get_bounds(item, &bounds);
+ double zoom = 0.50;
+ goo_canvas_item_scale(item, zoom, zoom);
+ goo_canvas_item_translate(item,
+ (-1 * bounds.x1 + x_start - 100) * zoom,
+ (-1 * bounds.y1 + y_start + 650) * zoom);
+ g_signal_connect(item, "button_press_event",
+ (GCallback) item_event_ok,
+ "fontface_reset");
+ gc_item_focus_init(item, NULL);
+
+ gchar *first_font_name = g_strdup_printf(_("Font: %s"), (char *)g_list_nth_data(fontlist, font_index));
+ item_font_text = goo_canvas_text_new (rootitem,
+ first_font_name,
(gdouble) x_text_start,
(gdouble) y_start,
-1,
@@ -445,9 +439,6 @@ gc_config_start ()
"font", gc_skin_font_content,
"fill-color-rgba", gc_skin_color_content,
NULL);
- g_free(first_skin_name);
- g_free(skin_dir);
-
}
// Difficulty Filter
@@ -493,6 +484,9 @@ void gc_config_stop ()
stars_group = NULL;
+ g_list_free(fontlist);
+ fontlist = NULL;
+
/* UnPause the board */
if(is_displayed)
gc_board_pause(FALSE);
@@ -740,6 +734,23 @@ get_previous_locale(gchar *locale)
return(locale);
}
+static void _update_font()
+{
+ gchar *font_str;
+ gchar *display_font;
+
+ font_str = g_strdup_printf(_("Font: %s"),
+ (char *)g_list_nth_data(fontlist, font_index));
+ display_font = g_strdup_printf("%s 12",
+ (char *)g_list_nth_data(fontlist, font_index));
+ g_object_set (G_OBJECT(item_font_text),
+ "text", font_str,
+ "font", display_font,
+ NULL);
+ g_free(font_str);
+ g_free(display_font);
+}
+
/* Callback for the bar operations */
static gint
item_event_ok(GooCanvasItem *item,
@@ -767,10 +778,11 @@ item_event_ok(GooCanvasItem *item,
} else {
gc_locale_set(current_locale);
}
- g_free(properties->skin);
- properties->skin = g_strdup((char *)g_list_nth_data(skinlist, skin_index));
- gc_skin_load(properties->skin);
- gc_config_stop();
+
+ // Font Face
+ g_free(properties->fontface);
+ properties->fontface = g_strdup((char *)g_list_nth_data(fontlist, font_index));
+ gc_skin_update_font();
if(properties->music || properties->fx)
gc_sound_init();
@@ -786,6 +798,7 @@ item_event_ok(GooCanvasItem *item,
gc_sound_fx_close();
}
gc_prop_save(properties);
+ gc_config_stop();
}
else if(!strcmp((char *)data, "rememberlevel"))
{
@@ -887,32 +900,24 @@ item_event_ok(GooCanvasItem *item,
"text", gettext(timername[properties->timer]),
NULL);
}
- else if(!strcmp((char *)data, "skin_previous"))
+ else if(!strcmp((char *)data, "font_previous"))
{
- gchar *skin_str;
- if(skin_index-- < 1)
- skin_index = g_list_length(skinlist)-1;
+ if(font_index-- < 1)
+ font_index = g_list_length(fontlist)-1;
- skin_str = g_strdup_printf(_("Skin : %s"),
- (char *)g_list_nth_data(skinlist, skin_index));
+ _update_font();
+ }
+ else if(!strcmp((char *)data, "font_next"))
+ {
+ if(font_index++ >= g_list_length(fontlist)-1)
+ font_index = 0;
- g_object_set (G_OBJECT(item_skin_text),
- "text", skin_str,
- NULL);
- g_free(skin_str);
+ _update_font();
}
- else if(!strcmp((char *)data, "skin_next"))
+ else if(!strcmp((char *)data, "fontface_reset"))
{
- gchar *skin_str;
- if(skin_index++ >= g_list_length(skinlist)-1)
- skin_index = 0;
-
- skin_str = g_strdup_printf(_("Skin : %s"),
- (char *)g_list_nth_data(skinlist, skin_index));
- g_object_set (G_OBJECT(item_skin_text),
- "text", skin_str,
- NULL);
- g_free(skin_str);
+ font_index = current_font_index;
+ _update_font();
}
return TRUE;
diff --git a/src/gcompris/gcompris.h b/src/gcompris/gcompris.h
index caf28e4..b34f0b7 100644
--- a/src/gcompris/gcompris.h
+++ b/src/gcompris/gcompris.h
@@ -251,7 +251,6 @@ gint gc_timing (gint timeout, gint actors_number);
#define COLOR_SUBTITLE 0xB00400FF
#define COLOR_SHADOW 0x000000FF
-#define FONT_FONTFACE "sans"
#define FONT_TITLE "sans 20"
#define FONT_TITLE_FALLBACK "sans 12"
#define FONT_SUBTITLE "sans 16"
diff --git a/src/gcompris/properties.c b/src/gcompris/properties.c
index 03bc7f4..cded23c 100644
--- a/src/gcompris/properties.c
+++ b/src/gcompris/properties.c
@@ -153,6 +153,7 @@ gc_prop_new ()
tmp->nocursor = 0;
tmp->timer = 1;
tmp->skin = g_strdup("babytoy");
+ tmp->fontface = g_strdup("Sans");
tmp->key = g_strdup("default");
tmp->locale = NULL;
tmp->difficulty_max = 0;
@@ -415,10 +416,10 @@ gc_prop_load (GcomprisProperties *props, GCPropSourceConf source_conf)
} else if(!strcmp(value.v_identifier, "filter_style")) {
if(!scan_get_int(scanner, &props->filter_style))
g_warning("Config file parsing error on token %s", token);
- } else if(!strcmp(value.v_identifier, "skin")) {
- g_free(props->skin);
- props->skin = scan_get_string(scanner);
- if(!props->skin)
+ } else if(!strcmp(value.v_identifier, "fontface")) {
+ g_free(props->fontface);
+ props->fontface = scan_get_string(scanner);
+ if(!props->fontface)
g_warning("Config file parsing error on token %s", token);
} else if(!strcmp(value.v_identifier, "user_dir")) {
g_free(props->user_dir);
@@ -539,6 +540,7 @@ gc_prop_destroy (GcomprisProperties *props)
g_free(props->system_icon_dir);
g_free(props->locale);
g_free(props->skin);
+ g_free(props->fontface);
g_free(props->key);
gc_profile_destroy(props->profile);
gc_user_destroy(props->logged_user);
@@ -568,7 +570,7 @@ gc_prop_save (GcomprisProperties *props)
fprintf(filefd, "%s=%d\n", "fullscreen", props->fullscreen);
fprintf(filefd, "%s=%d\n", "timer", props->timer);
- fprintf(filefd, "%s=\"%s\"\n", "skin", props->skin);
+ fprintf(filefd, "%s=\"%s\"\n", "fontface", props->fontface);
fprintf(filefd, "%s=\"%s\"\n", "locale", props->locale);
fprintf(filefd, "%s=\"%s\"\n", "key", props->key);
diff --git a/src/gcompris/properties.h b/src/gcompris/properties.h
index 86c6ff5..00630c3 100644
--- a/src/gcompris/properties.h
+++ b/src/gcompris/properties.h
@@ -53,6 +53,7 @@ typedef struct {
gchar *system_icon_dir;
gchar *locale;
gchar *skin;
+ gchar *fontface;
gchar *key;
GcomprisProfile *profile;
GcomprisUser *logged_user;
diff --git a/src/gcompris/skin.c b/src/gcompris/skin.c
index a53135b..e6d5619 100644
--- a/src/gcompris/skin.c
+++ b/src/gcompris/skin.c
@@ -22,7 +22,11 @@
#include <libxml/tree.h>
#include <libxml/parser.h>
+// The font info from the skin.xml file
+GHashTable* gc_skin_xmlfonts = NULL;
+// The face + font info ready to be used
GHashTable* gc_skin_fonts = NULL;
+
GHashTable* gc_skin_colors = NULL;
GHashTable* gc_skin_numbers = NULL;
@@ -32,7 +36,6 @@ guint32 gc_skin_color_content;
guint32 gc_skin_color_subtitle;
guint32 gc_skin_color_shadow;
-gchar* gc_skin_font_fontface;
gchar* gc_skin_font_title;
gchar* gc_skin_font_subtitle;
gchar* gc_skin_font_content;
@@ -194,8 +197,6 @@ gc_skin_setup_vars(void)
gc_skin_color_shadow =
gc_skin_get_color_default("gcompris/shadow", COLOR_SHADOW);
- gc_skin_font_fontface =
- gc_skin_get_font_default("gcompris/fontface", FONT_FONTFACE);
gc_skin_font_title =
gc_skin_get_font_default("gcompris/title", FONT_TITLE);
gc_skin_font_subtitle =
@@ -390,7 +391,7 @@ skin_xml_load (gchar* skin)
key = (gchar *)xmlGetProp(node, BAD_CAST "id");
data = (gchar *)xmlGetProp(node, BAD_CAST "name");
if((key!=NULL)&&(data!=NULL)){
- g_hash_table_insert(gc_skin_fonts, key, data);
+ g_hash_table_insert(gc_skin_xmlfonts, key, data);
} else {
if(key!=NULL) g_free(key);
if(data!=NULL) g_free(data);
@@ -429,6 +430,9 @@ gc_skin_load (gchar* skin)
gc_skin_free();
+ gc_skin_xmlfonts = g_hash_table_new_full(g_str_hash, g_str_equal,
+ gc_skin_free_string,
+ gc_skin_free_string);
gc_skin_fonts = g_hash_table_new_full(g_str_hash, g_str_equal,
gc_skin_free_string,
gc_skin_free_string);
@@ -445,6 +449,7 @@ gc_skin_load (gchar* skin)
return FALSE;
gc_skin_setup_vars();
+ gc_skin_update_font();
return TRUE;
}
@@ -454,6 +459,9 @@ gc_skin_load (gchar* skin)
void
gc_skin_free (void)
{
+ if(gc_skin_xmlfonts!=NULL)
+ g_hash_table_destroy(gc_skin_xmlfonts);
+
if(gc_skin_fonts!=NULL)
g_hash_table_destroy(gc_skin_fonts);
@@ -517,3 +525,37 @@ gc_skin_get_number_default(gchar* id, guint32 def)
return GPOINTER_TO_UINT(result);
return def;
}
+
+/*
+ * Update gc_skin_fonts
+ * Must be called whenever the font face is changed
+ */
+void
+gc_skin_update_font()
+{
+ GcomprisProperties *properties = gc_prop_get();
+
+ if(gc_skin_fonts!=NULL)
+ g_hash_table_destroy(gc_skin_fonts);
+
+ gc_skin_fonts = g_hash_table_new_full(g_str_hash, g_str_equal,
+ gc_skin_free_string,
+ gc_skin_free_string);
+
+ GHashTableIter iter;
+ int size = g_hash_table_size(gc_skin_fonts);
+
+ gchar *val;
+ gchar *key;
+
+ g_hash_table_iter_init (&iter, gc_skin_xmlfonts);
+ while (g_hash_table_iter_next (&iter, (gpointer) &key, (gpointer) &val))
+ {
+ gchar *font = g_strdup_printf("%s %s", properties->fontface, val);
+ g_hash_table_insert(gc_skin_fonts, (gpointer)g_strdup(key), (gpointer)font);
+ }
+ g_hash_table_insert(gc_skin_fonts, g_strdup("gcompris/fontface"), g_strdup(properties->fontface));
+
+ gc_skin_setup_vars();
+}
+
diff --git a/src/gcompris/skin.h b/src/gcompris/skin.h
index 6be55c9..2f08228 100644
--- a/src/gcompris/skin.h
+++ b/src/gcompris/skin.h
@@ -28,7 +28,6 @@ extern guint32 gc_skin_color_content;
extern guint32 gc_skin_color_subtitle;
extern guint32 gc_skin_color_shadow;
-extern gchar* gc_skin_font_fontface;
extern gchar* gc_skin_font_title;
extern gchar* gc_skin_font_subtitle;
extern gchar* gc_skin_font_content;
@@ -60,6 +59,7 @@ guint32 gc_skin_get_color_default(gchar* id, guint32 def);
void gc_skin_get_gdkcolor_default(gchar* id, guint32 def, GdkColor *gdkcolor);
gchar* gc_skin_get_font_default(gchar* id, gchar* def);
guint32 gc_skin_get_number_default(gchar* id, guint32 def);
+void gc_skin_update_font();
#define gc_skin_get_gdkcolor(id, gdkcolor) gc_skin_get_gdkcolor_default(id, 0x0D0DFA00, gdkcolor)
#define gc_skin_get_color(id) gc_skin_get_color_default(id, 0x0D0DFA00)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]