Fixed colortable
This commit is contained in:
parent
2b76716bee
commit
823b87abcd
|
@ -41,7 +41,6 @@ static const GmColorTableSchemeItem scheme_default[] = {
|
||||||
{"fg_cyan_h", "#86EEFFFFFFFF"},
|
{"fg_cyan_h", "#86EEFFFFFFFF"},
|
||||||
{"fg_white_h", "#807D74"},
|
{"fg_white_h", "#807D74"},
|
||||||
|
|
||||||
//{"bg_default", "#EAE8E3"},
|
|
||||||
{"bg_default", "#FFFFFF"},
|
{"bg_default", "#FFFFFF"},
|
||||||
{"bg_black", "#000000"},
|
{"bg_black", "#000000"},
|
||||||
{"bg_red", "#663822"},
|
{"bg_red", "#663822"},
|
||||||
|
@ -176,93 +175,11 @@ gm_color_table_item_free(gpointer item) {
|
||||||
g_free(i);
|
g_free(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gm_color_table_load_scheme(GmColorTable *table,
|
gm_color_table_set_value(GmColorTable *table, gchar const *name,
|
||||||
GmColorTableScheme scheme) {
|
gchar const *hex) {
|
||||||
int i = 0;
|
|
||||||
const GmColorTableSchemeItem *values = scheme_names[scheme].values;
|
|
||||||
|
|
||||||
while (values[i].name != NULL) {
|
|
||||||
gm_color_table_set(table, values[i].name, values[i].hex);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
table->priv->scheme = scheme;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gm_color_table_initialize(GmColorTable *table) {
|
|
||||||
gm_color_table_set_font_description(table, "Monospace 10");
|
|
||||||
gm_color_table_load_scheme(table, SCHEME_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gm_color_table_fill_from_options(GmColorTable *table) {
|
|
||||||
unsigned int i;
|
|
||||||
const gchar *value;
|
|
||||||
GmOptions *options = table->priv->options;
|
|
||||||
|
|
||||||
// New, color schemes
|
|
||||||
value = gm_options_get(options, "color_scheme");
|
|
||||||
|
|
||||||
if (value == NULL || strcmp(value, "user") == 0) {
|
|
||||||
for (i = 0; i < sizeof(ansi_colors) / sizeof(ansinamepair); i++) {
|
|
||||||
value = gm_options_get(options, ansi_colors[i].name);
|
|
||||||
|
|
||||||
if (value != NULL) {
|
|
||||||
gm_color_table_set(table, ansi_colors[i].name, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
gm_color_table_set_from_scheme_name(table, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
value = gm_options_get(options, "font_family");
|
|
||||||
|
|
||||||
if (value && *value != '\0') {
|
|
||||||
gm_color_table_set_font_description(table, value);
|
|
||||||
} else {
|
|
||||||
gm_options_set(options, "font_family", "Monospace 10");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Public functions */
|
|
||||||
|
|
||||||
GmColorTable *
|
|
||||||
gm_color_table_new(void) {
|
|
||||||
GmColorTable *table = GM_COLOR_TABLE(g_object_new(GM_TYPE_COLOR_TABLE, NULL));
|
|
||||||
|
|
||||||
gm_color_table_load_scheme(table, SCHEME_DEFAULT);
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
|
|
||||||
GmColorTable *
|
|
||||||
gm_color_table_new_from_options(gchar *filename) {
|
|
||||||
GmColorTable *table = GM_COLOR_TABLE(g_object_new(GM_TYPE_COLOR_TABLE, NULL));
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void gm_color_table_save(GmColorTable *table) {
|
|
||||||
if (table->priv->options) {
|
|
||||||
gm_options_save(table->priv->options);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gm_color_table_set(GmColorTable *table, const gchar *name, const gchar *hex) {
|
|
||||||
GmColorTableItem *item;
|
GmColorTableItem *item;
|
||||||
|
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);
|
||||||
|
@ -278,8 +195,112 @@ gm_color_table_set(GmColorTable *table, const gchar *name, const gchar *hex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gm_color_table_load_scheme(GmColorTable *table,
|
||||||
|
GmColorTableScheme scheme) {
|
||||||
|
guint i = 0;
|
||||||
|
GmColorTableSchemeItem const *values;
|
||||||
|
GmOptions *options = table->priv->options;
|
||||||
|
gchar const *value;
|
||||||
|
|
||||||
|
if (scheme == SCHEME_USER) {
|
||||||
|
for (i = 0; i < sizeof(ansi_colors) / sizeof(ansinamepair); ++i) {
|
||||||
|
value = gm_options_get(options, ansi_colors[i].name);
|
||||||
|
|
||||||
|
if (value != NULL) {
|
||||||
|
gm_color_table_set_value(table, ansi_colors[i].name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
values = scheme_names[scheme].values;
|
||||||
|
|
||||||
|
while (values[i].name != NULL) {
|
||||||
|
gm_color_table_set_value(table, values[i].name, values[i].hex);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
table->priv->scheme = scheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gm_color_table_initialize(GmColorTable *table) {
|
||||||
|
gm_color_table_set_font_description(table, "Monospace 10");
|
||||||
|
gm_color_table_load_scheme(table, SCHEME_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gm_color_table_fill_from_options(GmColorTable *table) {
|
||||||
|
gchar const *value;
|
||||||
|
GmOptions *options = table->priv->options;
|
||||||
|
|
||||||
|
// New, color schemes
|
||||||
|
value = gm_options_get(options, "color_scheme");
|
||||||
|
gm_color_table_set_from_scheme_name(table, gm_options_get(options,
|
||||||
|
"color_scheme"));
|
||||||
|
|
||||||
|
value = gm_options_get(options, "font_family");
|
||||||
|
|
||||||
|
if (value && *value != '\0') {
|
||||||
|
gm_color_table_set_font_description(table, value);
|
||||||
|
} else {
|
||||||
|
gm_options_set(options, "font_family", "Monospace 10");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Public functions */
|
||||||
|
|
||||||
|
GmColorTable *
|
||||||
|
gm_color_table_new(void) {
|
||||||
|
GmColorTable *table = GM_COLOR_TABLE(g_object_new(GM_TYPE_COLOR_TABLE,
|
||||||
|
NULL));
|
||||||
|
|
||||||
|
gm_color_table_load_scheme(table, SCHEME_DEFAULT);
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
GmColorTable *
|
||||||
|
gm_color_table_new_from_options(gchar *filename) {
|
||||||
|
GmColorTable *table = GM_COLOR_TABLE(g_object_new(GM_TYPE_COLOR_TABLE,
|
||||||
|
NULL));
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gm_color_table_save(GmColorTable *table) {
|
||||||
|
if (table->priv->options) {
|
||||||
|
gm_options_save(table->priv->options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gm_color_table_set(GmColorTable *table, gchar const *name, gchar const *hex) {
|
||||||
|
GmColorTableSchemeItem const *item;
|
||||||
|
GmColorTableItem *it;
|
||||||
|
|
||||||
|
if (table->priv->scheme != SCHEME_USER) {
|
||||||
|
table->priv->scheme = SCHEME_USER;
|
||||||
|
|
||||||
|
// Store all current values in the options
|
||||||
|
for (item = scheme_default; item->name != NULL; ++item) {
|
||||||
|
it = g_hash_table_lookup(table->priv->colors, item->name);
|
||||||
|
gm_options_set(table->priv->options, item->name, it->hex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store value in the options, set value in the table
|
||||||
|
gm_options_set(table->priv->options, name, hex);
|
||||||
|
gm_color_table_set_value(table, name, hex);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
gm_color_table_get(GmColorTable *table, const gchar *name, GdkColor *color) {
|
gm_color_table_get(GmColorTable *table, gchar const *name, GdkColor *color) {
|
||||||
GmColorTableItem *item;
|
GmColorTableItem *item;
|
||||||
|
|
||||||
item = g_hash_table_lookup(table->priv->colors, name);
|
item = g_hash_table_lookup(table->priv->colors, name);
|
||||||
|
@ -307,7 +328,7 @@ gm_color_table_get_hex(GmColorTable *table, const gchar *name) {
|
||||||
|
|
||||||
void
|
void
|
||||||
gm_color_table_set_font_description(GmColorTable *table,
|
gm_color_table_set_font_description(GmColorTable *table,
|
||||||
const gchar *font_description) {
|
gchar const *font_description) {
|
||||||
const gchar *fd;
|
const gchar *fd;
|
||||||
|
|
||||||
if (font_description == NULL) {
|
if (font_description == NULL) {
|
||||||
|
@ -335,12 +356,11 @@ gm_color_table_font_description(GmColorTable *table) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gm_color_table_set_from_scheme_name(GmColorTable *table, const gchar *scheme) {
|
gm_color_table_set_from_scheme_name(GmColorTable *table, gchar const *scheme) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (scheme_names[i].name != NULL) {
|
while (scheme_names[i].name != NULL) {
|
||||||
if (strcasecmp(scheme_names[i].name, scheme) == 0 &&
|
if (strcasecmp(scheme_names[i].name, scheme) == 0) {
|
||||||
scheme_names[i].values != NULL) {
|
|
||||||
gm_color_table_load_scheme(table, scheme_names[i].scheme);
|
gm_color_table_load_scheme(table, scheme_names[i].scheme);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,18 @@ 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), \
|
||||||
#define GM_COLOR_TABLE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GM_TYPE_COLOR_TABLE, GmColorTable const))
|
GM_TYPE_COLOR_TABLE, GmColorTable))
|
||||||
#define GM_COLOR_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GM_TYPE_COLOR_TABLE, GmColorTableClass))
|
#define GM_COLOR_TABLE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
|
||||||
#define GM_IS_COLOR_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GM_TYPE_COLOR_TABLE))
|
GM_TYPE_COLOR_TABLE, GmColorTable const))
|
||||||
#define GM_IS_COLOR_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GM_TYPE_COLOR_TABLE))
|
#define GM_COLOR_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
|
||||||
#define GM_COLOR_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GM_TYPE_COLOR_TABLE, GmColorTableClass))
|
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_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))
|
||||||
|
|
||||||
/* Private structure type */
|
/* Private structure type */
|
||||||
typedef struct _GmColorTablePrivate GmColorTablePrivate;
|
typedef struct _GmColorTablePrivate GmColorTablePrivate;
|
||||||
|
@ -58,20 +64,20 @@ GmColorTable *gm_color_table_new(void);
|
||||||
GmColorTable *gm_color_table_new_from_options(gchar *filename);
|
GmColorTable *gm_color_table_new_from_options(gchar *filename);
|
||||||
void gm_color_table_save(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, gchar const *name,
|
||||||
const gchar *hex);
|
gchar const *hex);
|
||||||
gboolean gm_color_table_get(GmColorTable *table, const gchar *name,
|
gboolean gm_color_table_get(GmColorTable *table, gchar const *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, gchar const *name);
|
||||||
|
|
||||||
void gm_color_table_set_font_description(GmColorTable *table,
|
void gm_color_table_set_font_description(GmColorTable *table,
|
||||||
const gchar *font_description);
|
gchar const *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,
|
void gm_color_table_load_scheme(GmColorTable *table,
|
||||||
GmColorTableScheme scheme);
|
GmColorTableScheme scheme);
|
||||||
void gm_color_table_set_from_scheme_name(GmColorTable *table,
|
void gm_color_table_set_from_scheme_name(GmColorTable *table,
|
||||||
const gchar *name);
|
gchar const *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
|
||||||
|
|
Reference in New Issue