Display theme implementation
It has only built in display themes yet.
This commit is contained in:
parent
4549c9fab3
commit
0dc80e431b
@ -13,13 +13,14 @@ BUILT_SOURCES = \
|
||||
$(NULL)
|
||||
|
||||
astrognome_source_files = \
|
||||
ag-app.c \
|
||||
ag-window.c \
|
||||
ag-chart.c \
|
||||
ag-settings.c \
|
||||
ag-preferences.c \
|
||||
ag-db.c \
|
||||
astrognome.c \
|
||||
ag-app.c \
|
||||
ag-window.c \
|
||||
ag-chart.c \
|
||||
ag-settings.c \
|
||||
ag-preferences.c \
|
||||
ag-db.c \
|
||||
ag-display-theme.c \
|
||||
astrognome.c \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = \
|
||||
|
276
src/ag-display-theme.c
Normal file
276
src/ag-display-theme.c
Normal file
@ -0,0 +1,276 @@
|
||||
#include <glib/gi18n.h>
|
||||
#include <swe-glib.h>
|
||||
|
||||
#include "astrognome.h"
|
||||
#include "ag-display-theme.h"
|
||||
|
||||
static gchar *planet_all = ".planet {\n" \
|
||||
" visibility: visible;\n" \
|
||||
"}\n";
|
||||
|
||||
static gchar *planet_none = ".planet {\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 gchar *builtin_theme_name[AG_DISPLAY_THEME_COUNT] = {
|
||||
NC_("Display theme name", "Everything"),
|
||||
NC_("Display theme name", "Classic"),
|
||||
};
|
||||
|
||||
gchar *
|
||||
ag_display_theme_to_css(AgDisplayTheme *theme)
|
||||
{
|
||||
GList *i;
|
||||
gchar *ret;
|
||||
GString *css = NULL;
|
||||
|
||||
if (theme->planets_include) {
|
||||
css = g_string_new(planet_none);
|
||||
} else {
|
||||
css = g_string_new(planet_all);
|
||||
}
|
||||
|
||||
for (i = theme->planets; i; i = g_list_next(i)) {
|
||||
const gchar *planet_name;
|
||||
|
||||
planet_name = ag_planet_id_to_nick(GPOINTER_TO_INT(i->data));
|
||||
|
||||
g_string_append_printf(
|
||||
css,
|
||||
planet_tmpl,
|
||||
planet_name,
|
||||
(theme->planets_include) ? "visible" : "hidden"
|
||||
);
|
||||
}
|
||||
|
||||
if (theme->aspects_include) {
|
||||
g_string_append(css, aspect_none);
|
||||
} else {
|
||||
g_string_append(css, aspect_all);
|
||||
}
|
||||
|
||||
for (i = theme->aspects; i; i = g_list_next(i)) {
|
||||
const gchar *aspect_name;
|
||||
|
||||
aspect_name = ag_aspect_id_to_nick(GPOINTER_TO_INT(i->data));
|
||||
|
||||
g_string_append_printf(
|
||||
css,
|
||||
aspect_tmpl,
|
||||
aspect_name,
|
||||
(theme->aspects_include) ? "visible" : "hidden"
|
||||
);
|
||||
}
|
||||
|
||||
if (theme->antiscia_include) {
|
||||
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);
|
||||
|
||||
g_debug("%s", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static AgDisplayTheme *
|
||||
ag_display_theme_get_builtin(gint id)
|
||||
{
|
||||
AgDisplayTheme *theme;
|
||||
|
||||
// Builtin themes all have a negative ID
|
||||
g_return_val_if_fail(id < 0, NULL);
|
||||
// And must be greater then AG_DISPLAY_THEME_COUNT
|
||||
g_return_val_if_fail(id >= -AG_DISPLAY_THEME_COUNT, NULL);
|
||||
|
||||
if (builtin_themes == NULL) {
|
||||
builtin_themes = g_new0(AgDisplayTheme *, AG_DISPLAY_THEME_COUNT);
|
||||
}
|
||||
|
||||
// If the theme is already created, return it
|
||||
if (builtin_themes[-id] != NULL) {
|
||||
return builtin_themes[-id];
|
||||
}
|
||||
|
||||
theme = builtin_themes[-id] = g_new0(AgDisplayTheme, 1);
|
||||
|
||||
switch (id) {
|
||||
case AG_DISPLAY_THEME_ALL:
|
||||
theme->id = id;
|
||||
theme->name = gettext(builtin_theme_name[-id - 1]);
|
||||
theme->builtin = TRUE;
|
||||
theme->planets_include = FALSE;
|
||||
theme->planets = NULL;
|
||||
theme->aspects_include = FALSE;
|
||||
theme->aspects = NULL;
|
||||
theme->antiscia_include = FALSE;
|
||||
theme->antiscia = NULL;
|
||||
|
||||
break;
|
||||
|
||||
case AG_DISPLAY_THEME_CLASSIC:
|
||||
// TODO: If SWE-GLib would support it, we could programatically get
|
||||
// classic planets and aspects here, thus, if it is messed up,
|
||||
// we need to fix it only once.
|
||||
theme->id = id;
|
||||
theme->name = gettext(builtin_theme_name[-id - 1]);
|
||||
theme->builtin = TRUE;
|
||||
theme->planets_include = TRUE;
|
||||
theme->planets = NULL;
|
||||
theme->aspects_include = TRUE;
|
||||
theme->aspects = NULL;
|
||||
theme->antiscia_include = TRUE;
|
||||
theme->antiscia = NULL;
|
||||
|
||||
theme->planets = g_list_prepend(
|
||||
theme->planets,
|
||||
GINT_TO_POINTER(GSWE_PLANET_SUN)
|
||||
);
|
||||
theme->planets = g_list_prepend(
|
||||
theme->planets,
|
||||
GINT_TO_POINTER(GSWE_PLANET_MOON)
|
||||
);
|
||||
theme->planets = g_list_prepend(
|
||||
theme->planets,
|
||||
GINT_TO_POINTER(GSWE_PLANET_MERCURY)
|
||||
);
|
||||
theme->planets = g_list_prepend(
|
||||
theme->planets,
|
||||
GINT_TO_POINTER(GSWE_PLANET_VENUS)
|
||||
);
|
||||
theme->planets = g_list_prepend(
|
||||
theme->planets,
|
||||
GINT_TO_POINTER(GSWE_PLANET_MARS)
|
||||
);
|
||||
theme->planets = g_list_prepend(
|
||||
theme->planets,
|
||||
GINT_TO_POINTER(GSWE_PLANET_JUPITER)
|
||||
);
|
||||
theme->planets = g_list_prepend(
|
||||
theme->planets,
|
||||
GINT_TO_POINTER(GSWE_PLANET_SATURN)
|
||||
);
|
||||
theme->planets = g_list_prepend(
|
||||
theme->planets,
|
||||
GINT_TO_POINTER(GSWE_PLANET_MOON_NODE)
|
||||
);
|
||||
|
||||
theme->aspects = g_list_prepend(
|
||||
theme->aspects,
|
||||
GINT_TO_POINTER(GSWE_ASPECT_CONJUCTION)
|
||||
);
|
||||
theme->aspects = g_list_prepend(
|
||||
theme->aspects,
|
||||
GINT_TO_POINTER(GSWE_ASPECT_OPPOSITION)
|
||||
);
|
||||
theme->aspects = g_list_prepend(
|
||||
theme->aspects,
|
||||
GINT_TO_POINTER(GSWE_ASPECT_TRINE)
|
||||
);
|
||||
theme->aspects = g_list_prepend(
|
||||
theme->aspects,
|
||||
GINT_TO_POINTER(GSWE_ASPECT_SQUARE)
|
||||
);
|
||||
theme->aspects = g_list_prepend(
|
||||
theme->aspects,
|
||||
GINT_TO_POINTER(GSWE_ASPECT_SEXTILE)
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
g_free(theme);
|
||||
g_warning("Trying to instantiate unknown builtin theme %d", id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
GList *
|
||||
ag_display_theme_get_list(void)
|
||||
{
|
||||
int i;
|
||||
GList *ret = NULL;
|
||||
|
||||
for (i = 1; i <= AG_DISPLAY_THEME_COUNT; i++) {
|
||||
AgDisplayTheme *theme = ag_display_theme_get_builtin(-i);
|
||||
|
||||
ret = g_list_append(ret, theme);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AgDisplayTheme *
|
||||
ag_display_theme_get_by_id(int id)
|
||||
{
|
||||
if (id < 0) {
|
||||
return ag_display_theme_get_builtin(id);
|
||||
}
|
||||
|
||||
g_warning("Invalid theme ID. Falling back to display everything.");
|
||||
|
||||
return ag_display_theme_get_builtin(AG_DISPLAY_THEME_ALL);
|
||||
}
|
||||
|
||||
void
|
||||
ag_display_theme_free(AgDisplayTheme *display_theme)
|
||||
{
|
||||
if (!display_theme || display_theme->builtin)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g_free(display_theme->name);
|
||||
g_list_free(display_theme->planets);
|
||||
g_list_free(display_theme->aspects);
|
||||
g_list_free(display_theme->antiscia);
|
||||
g_free(display_theme);
|
||||
}
|
33
src/ag-display-theme.h
Normal file
33
src/ag-display-theme.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef __AG_DISPLAY_THEME_H__
|
||||
#define __AG_DISPLAY_THEME_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
typedef struct _AgDisplayTheme {
|
||||
gint id;
|
||||
gchar *name;
|
||||
gboolean builtin;
|
||||
gboolean planets_include;
|
||||
GList *planets;
|
||||
gboolean aspects_include;
|
||||
GList *aspects;
|
||||
gboolean antiscia_include;
|
||||
GList *antiscia;
|
||||
} AgDisplayTheme;
|
||||
|
||||
enum {
|
||||
AG_DISPLAY_THEME_ALL = -1,
|
||||
AG_DISPLAY_THEME_CLASSIC = -2,
|
||||
AG_DISPLAY_THEME_PREV,
|
||||
AG_DISPLAY_THEME_COUNT = - AG_DISPLAY_THEME_PREV + 1
|
||||
};
|
||||
|
||||
gchar *ag_display_theme_to_css(AgDisplayTheme *display_theme);
|
||||
|
||||
AgDisplayTheme *ag_display_theme_get_by_id(int id);
|
||||
|
||||
GList *ag_display_theme_get_list(void);
|
||||
|
||||
void ag_display_theme_free(AgDisplayTheme *display_theme);
|
||||
|
||||
#endif /* __AG_DISPLAY_THEME_H__ */
|
Loading…
Reference in New Issue
Block a user