Added schemes

This commit is contained in:
Jesse van den Kieboom 2005-11-06 16:00:32 +00:00
parent e56d1bd36a
commit 1fac238caf
2 changed files with 190 additions and 114 deletions

View file

@ -15,17 +15,104 @@ struct _GmColorTableItem {
GdkColor color; GdkColor color;
}; };
typedef struct _GmColorTableSchemeItem {
const gchar *name;
const gchar *hex;
} GmColorTableSchemeItem;
static const GmColorTableSchemeItem scheme_default[] = {
{"fg_default", "#000000"},
{"fg_black", "#000000"},
{"fg_red", "#663822"},
{"fg_green", "#445632"},
{"fg_yellow", "#D1940C"},
{"fg_blue", "#314E6C"},
{"fg_purple", "#494066"},
{"fg_cyan", "#0000FFFFFFFF"},
{"fg_white", "#BAB5AB"},
{"fg_default_h", "#565248"},
{"fg_black_h", "#565248"},
{"fg_red_h", "#990000"},
{"fg_green_h", "#267726"},
{"fg_yellow_h", "#EED680"},
{"fg_blue_h", "#9DB8D2"},
{"fg_purple_h", "#ADA7C8"},
{"fg_cyan_h", "#86EEFFFFFFFF"},
{"fg_white_h", "#807D74"},
//{"bg_default", "#EAE8E3"},
{"bg_default", "#FFFFFF"},
{"bg_black", "#000000"},
{"bg_red", "#663822"},
{"bg_green", "#445632"},
{"bg_yellow", "#D1940C"},
{"bg_blue", "#314E6C"},
{"bg_purple", "#494066"},
{"bg_cyan", "#0000FFFFFFFF"},
{"bg_white", "#FFFFFFFFFFFF"},
{NULL, NULL}
};
static const GmColorTableSchemeItem scheme_white_on_black[] = {
{"fg_default", "#D6B5D6B5D6B5"},
{"fg_black", "#2D6B2D6B2D6B"},
{"fg_red", "#FFFF00000000"},
{"fg_green", "#0000FFFF0000"},
{"fg_yellow", "#FFFFD0450000"},
{"fg_blue", "#3EF73EF7BFFF"},
{"fg_purple", "#A0A02020F0F0"},
{"fg_cyan", "#0000FFFFFFFF"},
{"fg_white", "#D8C5D8C5D8C5"},
{"fg_default_h", "#FFFFFFFFFFFF"},
{"fg_black_h", "#529452945294"},
{"fg_red_h", "#FFFF785F785F"},
{"fg_green_h", "#66ADFFFF66AD"},
{"fg_yellow_h", "#FFFFFFFF58C6"},
{"fg_blue_h", "#86318631FFFF"},
{"fg_purple_h", "#C6576A18FFFF"},
{"fg_cyan_h", "#86EEFFFFFFFF"},
{"fg_white_h", "#FFFFFFFFFFFF"},
{"bg_default", "#000000000000"},
{"bg_black", "#2B5B2B5B2B5B"},
{"bg_red", "#FFFF00000000"},
{"bg_green", "#000080000000"},
{"bg_yellow", "#C047C0470000"},
{"bg_blue", "#00000000FFFF"},
{"bg_purple", "#A0A02020F0F0"},
{"bg_cyan", "#0000B74CB74C"},
{"bg_white", "#FFFFFFFFFFFF"},
{NULL, NULL}
};
typedef struct _GmColorScheme {
GmColorTableScheme scheme;
const gchar *name;
const GmColorTableSchemeItem *values;
} GmColorScheme;
static const GmColorScheme scheme_names[] = {
{SCHEME_NONE, "none", NULL},
{SCHEME_DEFAULT, "default", scheme_default},
{SCHEME_WHITE_ON_BLACK, "white_on_black", scheme_white_on_black},
{SCHEME_USER, "user", NULL},
{SCHEME_NONE, NULL, NULL}
};
struct _GmColorTablePrivate { struct _GmColorTablePrivate {
gboolean bold;
GHashTable *colors; GHashTable *colors;
gchar *font_description; gchar *font_description;
GmOptions *options;
GmColorTableScheme scheme;
}; };
/* Signals */ /* Signals */
enum { enum {
COLOR_CHANGED, COLOR_CHANGED,
BOLD_TOGGLED,
FONT_CHANGED, FONT_CHANGED,
NUM_SIGNALS NUM_SIGNALS
}; };
@ -58,17 +145,6 @@ gm_color_table_class_init(GmColorTableClass *klass) {
1, 1,
G_TYPE_STRING); G_TYPE_STRING);
color_table_signals[BOLD_TOGGLED] =
g_signal_new("bold_toggled",
G_OBJECT_CLASS_TYPE(object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(GmColorTableClass, bold_toggled),
NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE,
1,
G_TYPE_BOOLEAN);
color_table_signals[FONT_CHANGED] = color_table_signals[FONT_CHANGED] =
g_signal_new("font_changed", g_signal_new("font_changed",
G_OBJECT_CLASS_TYPE(object_class), G_OBJECT_CLASS_TYPE(object_class),
@ -88,6 +164,7 @@ gm_color_table_init(GmColorTable *table) {
table->priv = GM_COLOR_TABLE_GET_PRIVATE(table); table->priv = GM_COLOR_TABLE_GET_PRIVATE(table);
table->priv->colors = g_hash_table_new_full(g_str_hash, g_str_equal, table->priv->colors = g_hash_table_new_full(g_str_hash, g_str_equal,
g_free, gm_color_table_item_free); g_free, gm_color_table_item_free);
table->priv->scheme = SCHEME_NONE;
} }
/* Private functions */ /* Private functions */
@ -100,69 +177,53 @@ gm_color_table_item_free(gpointer item) {
} }
void void
gm_color_table_initialize(GmColorTable *table) { gm_color_table_load_scheme(GmColorTable *table,
gm_color_table_set_bold(table, FALSE); GmColorTableScheme scheme) {
gm_color_table_set_font_description(table, "Monospace 10"); int i = 0;
const GmColorTableSchemeItem *values = scheme_names[scheme].values;
/*gm_color_table_set(table, "fg_default", "#D6B5D6B5D6B5"); while (values[i].name != NULL) {
gm_color_table_set(table, "fg_black", "#2D6B2D6B2D6B"); gm_color_table_set(table, values[i].name, values[i].hex);
gm_color_table_set(table, "fg_red", "#FFFF00000000"); ++i;
gm_color_table_set(table, "fg_green", "#0000FFFF0000"); }
gm_color_table_set(table, "fg_yellow", "#FFFFD0450000");
gm_color_table_set(table, "fg_blue", "#3EF73EF7BFFF"); table->priv->scheme = scheme;
gm_color_table_set(table, "fg_purple", "#A0A02020F0F0"); }
gm_color_table_set(table, "fg_cyan", "#0000FFFFFFFF");
gm_color_table_set(table, "fg_white", "#D8C5D8C5D8C5");
gm_color_table_set(table, "fg_default_h", "#FFFFFFFFFFFF"); void
gm_color_table_set(table, "fg_black_h", "#529452945294"); gm_color_table_initialize(GmColorTable *table) {
gm_color_table_set(table, "fg_red_h", "#FFFF785F785F"); gm_color_table_set_font_description(table, "Monospace 10");
gm_color_table_set(table, "fg_green_h", "#66ADFFFF66AD"); gm_color_table_load_scheme(table, SCHEME_DEFAULT);
gm_color_table_set(table, "fg_yellow_h", "#FFFFFFFF58C6"); }
gm_color_table_set(table, "fg_blue_h", "#86318631FFFF");
gm_color_table_set(table, "fg_purple_h", "#C6576A18FFFF");
gm_color_table_set(table, "fg_cyan_h", "#86EEFFFFFFFF");
gm_color_table_set(table, "fg_white_h", "#FFFFFFFFFFFF");
gm_color_table_set(table, "bg_default", "#000000000000"); void
gm_color_table_set(table, "bg_black", "#2B5B2B5B2B5B"); gm_color_table_fill_from_options(GmColorTable *table) {
gm_color_table_set(table, "bg_red", "#FFFF00000000"); unsigned int i;
gm_color_table_set(table, "bg_green", "#000080000000"); const gchar *value;
gm_color_table_set(table, "bg_yellow", "#C047C0470000"); GmOptions *options = table->priv->options;
gm_color_table_set(table, "bg_blue", "#00000000FFFF");
gm_color_table_set(table, "bg_purple", "#A0A02020F0F0"); // New, color schemes
gm_color_table_set(table, "bg_cyan", "#0000B74CB74C"); value = gm_options_get(options, "color_scheme");
gm_color_table_set(table, "bg_white", "#FFFFFFFFFFFF");*/
if (value == NULL || strcmp(value, "user") == 0) {
gm_color_table_set(table, "fg_default", "#000000"); for (i = 0; i < sizeof(ansi_colors) / sizeof(ansinamepair); i++) {
gm_color_table_set(table, "fg_black", "#000000"); value = gm_options_get(options, ansi_colors[i].name);
gm_color_table_set(table, "fg_red", "#663822");
gm_color_table_set(table, "fg_green", "#445632"); if (value != NULL) {
gm_color_table_set(table, "fg_yellow", "#D1940C"); gm_color_table_set(table, ansi_colors[i].name, value);
gm_color_table_set(table, "fg_blue", "#314E6C"); }
gm_color_table_set(table, "fg_purple", "#494066"); }
gm_color_table_set(table, "fg_cyan", "#0000FFFFFFFF"); } else {
gm_color_table_set(table, "fg_white", "#BAB5AB"); gm_color_table_set_from_scheme_name(table, value);
}
gm_color_table_set(table, "fg_default_h", "#565248");
gm_color_table_set(table, "fg_black_h", "#565248"); value = gm_options_get(options, "font_family");
gm_color_table_set(table, "fg_red_h", "#990000");
gm_color_table_set(table, "fg_green_h", "#267726"); if (value && *value != '\0') {
gm_color_table_set(table, "fg_yellow_h", "#EED680"); gm_color_table_set_font_description(table, value);
gm_color_table_set(table, "fg_blue_h", "#9DB8D2"); } else {
gm_color_table_set(table, "fg_purple_h", "#ADA7C8"); gm_options_set(options, "font_family", "Monospace 10");
gm_color_table_set(table, "fg_cyan_h", "#86EEFFFFFFFF"); }
gm_color_table_set(table, "fg_white_h", "#807D74");
gm_color_table_set(table, "bg_default", "#EAE8E3");
gm_color_table_set(table, "bg_black", "#000000");
gm_color_table_set(table, "bg_red", "#663822");
gm_color_table_set(table, "bg_green", "#445632");
gm_color_table_set(table, "bg_yellow", "#D1940C");
gm_color_table_set(table, "bg_blue", "#314E6C");
gm_color_table_set(table, "bg_purple", "#494066");
gm_color_table_set(table, "bg_cyan", "#0000FFFFFFFF");
gm_color_table_set(table, "bg_white", "#FFFFFFFFFFFF");
} }
/* Public functions */ /* Public functions */
@ -171,21 +232,26 @@ GmColorTable *
gm_color_table_new(void) { gm_color_table_new(void) {
GmColorTable *table = GM_COLOR_TABLE(g_object_new(GM_TYPE_COLOR_TABLE, NULL)); GmColorTable *table = GM_COLOR_TABLE(g_object_new(GM_TYPE_COLOR_TABLE, NULL));
gm_color_table_restore_defaults(table); gm_color_table_load_scheme(table, SCHEME_DEFAULT);
return table; return table;
} }
GmColorTable * GmColorTable *
gm_color_table_new_from_options(GmOptions *options) { gm_color_table_new_from_options(gchar *filename) {
GmColorTable *table = GM_COLOR_TABLE(g_object_new(GM_TYPE_COLOR_TABLE, NULL)); GmColorTable *table = GM_COLOR_TABLE(g_object_new(GM_TYPE_COLOR_TABLE, NULL));
gm_color_table_set_from_options(table, options); table->priv->options = gm_options_new();
gm_options_set(table->priv->options, "color_scheme", "default");
gm_options_load(table->priv->options, filename);
gm_color_table_fill_from_options(table);
return table; return table;
} }
void void gm_color_table_save(GmColorTable *table) {
gm_color_table_restore_defaults(GmColorTable *table) { if (table->priv->options) {
gm_color_table_initialize(table); gm_options_save(table->priv->options);
}
} }
void void
@ -194,6 +260,10 @@ gm_color_table_set(GmColorTable *table, const gchar *name, const gchar *hex) {
item = g_hash_table_lookup(table->priv->colors, name); item = g_hash_table_lookup(table->priv->colors, name);
if (table->priv->scheme == SCHEME_USER) {
gm_options_set(table->priv->options, name, hex);
}
if (!item) { if (!item) {
item = g_new0(GmColorTableItem, 1); item = g_new0(GmColorTableItem, 1);
g_hash_table_insert(table->priv->colors, g_strdup(name), item); g_hash_table_insert(table->priv->colors, g_strdup(name), item);
@ -235,20 +305,6 @@ gm_color_table_get_hex(GmColorTable *table, const gchar *name) {
} }
} }
void
gm_color_table_set_bold(GmColorTable *table, gboolean bold) {
if (table->priv->bold != bold) {
table->priv->bold = bold;
g_signal_emit(table, color_table_signals[BOLD_TOGGLED], 0, bold);
}
}
gboolean
gm_color_table_bold(GmColorTable *table) {
return table->priv->bold;
}
void void
gm_color_table_set_font_description(GmColorTable *table, gm_color_table_set_font_description(GmColorTable *table,
const gchar *font_description) { const gchar *font_description) {
@ -259,7 +315,10 @@ gm_color_table_set_font_description(GmColorTable *table,
} else { } else {
fd = font_description; fd = font_description;
} }
gm_options_set(table->priv->options, "font_family",
fd);
if (table->priv->font_description == NULL || if (table->priv->font_description == NULL ||
strcmp(table->priv->font_description, fd) != 0) { strcmp(table->priv->font_description, fd) != 0) {
g_free(table->priv->font_description); g_free(table->priv->font_description);
@ -276,19 +335,25 @@ gm_color_table_font_description(GmColorTable *table) {
} }
void void
gm_color_table_set_from_options(GmColorTable *table, GmOptions *options) { gm_color_table_set_from_scheme_name(GmColorTable *table, const gchar *scheme) {
unsigned int i; int i = 0;
const gchar *value;
for (i = 0; i < sizeof(ansi_colors) / sizeof(ansinamepair); i++) { while (scheme_names[i].name != NULL) {
value = gm_options_get(options, ansi_colors[i].name); if (strcasecmp(scheme_names[i].name, scheme) == 0 &&
scheme_names[i].values != NULL) {
if (value != NULL) { gm_color_table_load_scheme(table, scheme_names[i].scheme);
gm_color_table_set(table, ansi_colors[i].name, value); break;
} }
++i;
} }
gm_color_table_set_bold(table, gm_options_get_int(options, "bold-colors")); if (scheme_names[i].name == NULL) {
gm_color_table_set_font_description(table, gm_options_get(options, gm_color_table_load_scheme(table, SCHEME_DEFAULT);
"font-family"));
gm_options_set(table->priv->options, "color_scheme",
"default");
} else {
gm_options_set(table->priv->options, "color_scheme",
scheme_names[i].name);
}
} }

View file

@ -9,11 +9,11 @@ G_BEGIN_DECLS
/* /*
* Type checking and casting macros * Type checking and casting macros
*/ */
#define GM_TYPE_COLOR_TABLE (gm_color_table_get_type()) #define GM_TYPE_COLOR_TABLE (gm_color_table_get_type())
#define GM_COLOR_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GM_TYPE_COLOR_TABLE, GmColorTable)) #define GM_COLOR_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GM_TYPE_COLOR_TABLE, GmColorTable))
#define GM_COLOR_TABLE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GM_TYPE_COLOR_TABLE, GmColorTable const)) #define GM_COLOR_TABLE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GM_TYPE_COLOR_TABLE, GmColorTable const))
#define GM_COLOR_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GM_TYPE_COLOR_TABLE, GmColorTableClass)) #define GM_COLOR_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GM_TYPE_COLOR_TABLE, GmColorTableClass))
#define GM_IS_COLOR_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GM_TYPE_COLOR_TABLE)) #define GM_IS_COLOR_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GM_TYPE_COLOR_TABLE))
#define GM_IS_COLOR_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GM_TYPE_COLOR_TABLE)) #define GM_IS_COLOR_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GM_TYPE_COLOR_TABLE))
#define GM_COLOR_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GM_TYPE_COLOR_TABLE, GmColorTableClass)) #define GM_COLOR_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GM_TYPE_COLOR_TABLE, GmColorTableClass))
@ -42,25 +42,36 @@ struct _GmColorTableClass {
/* Signals */ /* Signals */
void (* color_changed) (GmColorTable *table, const gchar *color); void (* color_changed) (GmColorTable *table, const gchar *color);
void (* bold_toggled) (GmColorTable *table, gboolean bold);
void (* font_changed) (GmColorTable *table, const gchar *font_description); void (* font_changed) (GmColorTable *table, const gchar *font_description);
}; };
typedef enum _GmColorTableScheme {
SCHEME_NONE = 0,
SCHEME_DEFAULT = 1,
SCHEME_WHITE_ON_BLACK = 2,
SCHEME_USER = 3
} GmColorTableScheme;
GType gm_color_table_get_type(void) G_GNUC_CONST; GType gm_color_table_get_type(void) G_GNUC_CONST;
GmColorTable *gm_color_table_new(void); GmColorTable *gm_color_table_new(void);
GmColorTable *gm_color_table_new_from_options(GmOptions *options); GmColorTable *gm_color_table_new_from_options(gchar *filename);
void gm_color_table_restore_defaults(GmColorTable *table); void gm_color_table_save(GmColorTable *table);
void gm_color_table_set(GmColorTable *table, const gchar *name, void gm_color_table_set(GmColorTable *table, const gchar *name,
const gchar *hex); const gchar *hex);
gboolean gm_color_table_get(GmColorTable *table, const gchar *name, gboolean gm_color_table_get(GmColorTable *table, const gchar *name,
GdkColor *color); GdkColor *color);
const gchar *gm_color_table_get_hex(GmColorTable *table, const gchar *name); const gchar *gm_color_table_get_hex(GmColorTable *table, const gchar *name);
void gm_color_table_set_bold(GmColorTable *table, gboolean bold);
gboolean gm_color_table_bold(GmColorTable *table);
void gm_color_table_set_font_description(GmColorTable *table, void gm_color_table_set_font_description(GmColorTable *table,
const gchar *font_description); const gchar *font_description);
const gchar *gm_color_table_font_description(GmColorTable *table); const gchar *gm_color_table_font_description(GmColorTable *table);
void gm_color_table_load_scheme(GmColorTable *table,
GmColorTableScheme scheme);
void gm_color_table_set_from_scheme_name(GmColorTable *table,
const gchar *name);
void gm_color_table_set_from_options(GmColorTable *table, GmOptions *options); void gm_color_table_set_from_options(GmColorTable *table, GmOptions *options);
G_END_DECLS G_END_DECLS