Fix up ag_display_theme_to_css()

This now generates the correct rules. Fixes #85
This commit is contained in:
Gergely Polonkai 2014-09-22 01:20:07 +02:00
parent c1703e0f4f
commit 03aaf8ae1a

View File

@ -4,41 +4,11 @@
#include "astrognome.h" #include "astrognome.h"
#include "ag-display-theme.h" #include "ag-display-theme.h"
static gchar *planet_all = ".planet {\n" \ static gchar *planet_rule = ".planet-%s { visibility: hidden; }\n";
" visibility: visible;\n" \ static gchar *aspect_type_rule = ".aspect-%s { visibility: hidden; }\n";
"}\n"; static gchar *aspect_planet_rule = ".aspect-p-%s { visibility: hidden; }\n";
static gchar *antiscion_type_rule = ".antiscion-%s { visibility: hidden; }\n";
static gchar *planet_none = ".planet {\n" \ static gchar *antiscion_planet_rule = ".antiscion-p-%s { visibility: hidden; }\n";
" visibility: hidden;\n" \
" }\n";
static gchar *planet_tmpl = ".planet-%s {\n" \
" visibility: %s !important;\n" \
"}\n";
static gchar *aspect_all = ".aspect {\n" \
" visibility: visible;\n" \
"}\n";
static gchar *aspect_none = ".aspect {\n" \
" visibility: hidden;\n" \
" }\n";
static gchar *aspect_tmpl = ".aspect-%s {\n" \
" visibility: %s !important;\n" \
"}\n";
static gchar *antiscion_all = ".antiscion {\n" \
" visibility: visible;\n" \
"}\n";
static gchar *antiscion_none = ".antiscion {\n" \
" visibility: hidden;\n" \
"}\n";
static gchar *antiscion_tmpl = ".antiscion-%s {\n" \
" visibility: %s !important;\n" \
"}\n";
static AgDisplayTheme **builtin_themes = NULL; static AgDisplayTheme **builtin_themes = NULL;
static gchar *builtin_theme_name[AG_DISPLAY_THEME_COUNT] = { static gchar *builtin_theme_name[AG_DISPLAY_THEME_COUNT] = {
@ -50,7 +20,10 @@ static gchar *builtin_theme_name[AG_DISPLAY_THEME_COUNT] = {
gchar * gchar *
ag_display_theme_to_css(AgDisplayTheme *theme) ag_display_theme_to_css(AgDisplayTheme *theme)
{ {
GList *i; gint i;
GList *l,
*all_aspects,
*all_antiscion_axes;
gchar *ret; gchar *ret;
GString *css = NULL; GString *css = NULL;
@ -59,68 +32,72 @@ ag_display_theme_to_css(AgDisplayTheme *theme)
return g_strdup(""); return g_strdup("");
} }
if (theme->planets_include) { css = g_string_sized_new(300);
css = g_string_new(planet_none);
} else {
css = g_string_new(planet_all);
}
for (i = theme->planets; i; i = g_list_next(i)) { // Go through the used_planets array. If any of them is not listed
// by @theme, add a rule to hide it, and the respective aspects
// and antiscia
for (i = 0; i < used_planets_count; i++) {
gboolean in_list;
in_list = (g_list_find(theme->planets, GINT_TO_POINTER(used_planets[i])) != NULL);
if (theme->planets_include != in_list) {
const gchar *planet_name; const gchar *planet_name;
planet_name = ag_planet_id_to_nick(GPOINTER_TO_INT(i->data)); planet_name = ag_planet_id_to_nick(used_planets[i]);
g_string_append_printf( g_string_append_printf(css, planet_rule, planet_name);
css, g_string_append_printf(css, aspect_planet_rule, planet_name);
planet_tmpl, g_string_append_printf(css, antiscion_planet_rule, planet_name);
planet_name, }
(theme->planets_include) ? "visible" : "hidden"
);
} }
if (theme->aspects_include) { // Go through gswe_all_aspects(). If any of them is not listed by
g_string_append(css, aspect_none); // @theme, add a rule to hide it
} else { all_aspects = gswe_all_aspects();
g_string_append(css, aspect_all);
for (l = all_aspects; l; l = g_list_next(l)) {
const gchar *aspect_type;
gboolean in_list;
GsweAspect aspect;
GsweAspectInfo *aspect_info = l->data;
aspect = gswe_aspect_info_get_aspect(aspect_info);
in_list = (g_list_find(theme->aspects, GINT_TO_POINTER(aspect)) != NULL);
aspect_type = ag_aspect_id_to_nick(aspect);
if (theme->aspects_include != in_list) {
g_string_append_printf(css, aspect_type_rule, aspect_type);
}
} }
for (i = theme->aspects; i; i = g_list_next(i)) { g_list_free(all_aspects);
const gchar *aspect_name;
aspect_name = ag_aspect_id_to_nick(GPOINTER_TO_INT(i->data)); // Go through gswe_all_antiscion_axes(). If any of them is not
// listed by @theme, add a rule to hide it
all_antiscion_axes = gswe_all_antiscion_axes();
g_string_append_printf( for (l = all_antiscion_axes; l; l = g_list_next(l)) {
css, const gchar *antiscion_axis_type;
aspect_tmpl, gboolean in_list;
aspect_name, GsweAntiscionAxis antiscion_axis;
(theme->aspects_include) ? "visible" : "hidden" GsweAntiscionAxisInfo *antiscion_axis_info = l->data;
);
antiscion_axis = gswe_antiscion_axis_info_get_axis(antiscion_axis_info);
in_list = (g_list_find(theme->antiscia, GINT_TO_POINTER(antiscion_axis)) != NULL);
antiscion_axis_type = ag_antiscion_axis_id_to_nick(antiscion_axis);
if (theme->antiscia_include != in_list) {
g_string_append_printf(css, antiscion_type_rule, antiscion_axis_type);
}
} }
if (theme->antiscia_include) { g_list_free(all_antiscion_axes);
g_string_append(css, antiscion_none);
} else {
g_string_append(css, antiscion_all);
}
for (i = theme->antiscia; i; i = g_list_next(i)) {
const gchar *antiscion_axis_name;
antiscion_axis_name = ag_antiscion_axis_id_to_nick(
GPOINTER_TO_INT(i->data)
);
g_string_append_printf(
css,
antiscion_tmpl,
antiscion_axis_name,
(theme->antiscia_include) ? "visible" : "hidden"
);
}
ret = g_string_free(css, FALSE); ret = g_string_free(css, FALSE);
g_debug("%s", ret); g_debug("Generated CSS:\n%s\n", ret);
return ret; return ret;
} }