static void theme_data_cb(void *user_data, const char *element, char *const *attrs, const char *text) { state *s = (state *)user_data; if (!strcmp(element, "name")) set_string(&s->theme->name, text); else if (!strcmp(element, "style")) set_string(&s->theme->style, text); else if (!strcmp(element, "pieces")) set_string(&s->theme->pieces, text); else if (!strcmp(element, "board")) set_string(&s->theme->board, text); else if (!strcmp(element, "white_name")) set_string(&s->theme->white_name, text); else if (!strcmp(element, "black_name")) set_string(&s->theme->black_name, text); else if (!strcmp(element, "selector")) { int i = 0; while (attrs[i] && attrs[i + 1]) { if (!strcmp(attrs[i], "spinspeed")) s->theme->selector.spinspeed = atof(attrs[i + 1]); else if (!strcmp(attrs[i], "size")) s->theme->selector.size = atof(attrs[i + 1]); else if (!strcmp(attrs[i], "bouncespeed")) s->theme->selector.bouncespeed = atof(attrs[i + 1]); else if (!strcmp(attrs[i], "colour")) parse_rgba(attrs[i + 1], &s->theme->selector.colour[0], &s->theme->selector.colour[1], &s->theme->selector.colour[2], &s->theme->selector.colour[3]); i += 2; } } }
void thing_type_t::parse(Tokenizer *tz) { type = tz->get_integer(); name = tz->get_token(); if (tz->peek_token() == "{") { tz->check_token("{"); string token = tz->get_token(); while (token != "}") { if (token == "size") radius = tz->get_integer(); if (token == "colour") parse_rgba(tz, &colour); if (token == "sprite") { spritename = tz->get_token(); if (!(vector_exists(spritenames, spritename))) spritenames.push_back(spritename); } if (token == "angle") show_angle = tz->get_bool(); if (token == "hanging") hanging = tz->get_bool(); if (token == "arg1") args[0] = tz->get_token(); if (token == "arg2") args[1] = tz->get_token(); if (token == "arg3") args[2] = tz->get_token(); if (token == "arg4") args[3] = tz->get_token(); if (token == "arg5") args[4] = tz->get_token(); if (token == "arg1_type") arg_types[0] = tz->get_token(); if (token == "arg2_type") arg_types[1] = tz->get_token(); if (token == "arg3_type") arg_types[2] = tz->get_token(); if (token == "arg4_type") arg_types[3] = tz->get_token(); if (token == "arg5_type") arg_types[4] = tz->get_token(); token = tz->get_token(); } } }
/** * clutter_color_from_string: * @color: (out caller-allocates): return location for a #ClutterColor * @str: a string specifiying a color * * Parses a string definition of a color, filling the #ClutterColor.red, * #ClutterColor.green, #ClutterColor.blue and #ClutterColor.alpha fields * of @color. * * The @color is not allocated. * * The format of @str can be either one of: * * - a standard name (as taken from the X11 rgb.txt file) * - an hexadecimal value in the form: `#rgb`, `#rrggbb`, `#rgba`, or `#rrggbbaa` * - a RGB color in the form: `rgb(r, g, b)` * - a RGB color in the form: `rgba(r, g, b, a)` * - a HSL color in the form: `hsl(h, s, l)` * -a HSL color in the form: `hsla(h, s, l, a)` * * where 'r', 'g', 'b' and 'a' are (respectively) the red, green, blue color * intensities and the opacity. The 'h', 's' and 'l' are (respectively) the * hue, saturation and luminance values. * * In the rgb() and rgba() formats, the 'r', 'g', and 'b' values are either * integers between 0 and 255, or percentage values in the range between 0% * and 100%; the percentages require the '%' character. The 'a' value, if * specified, can only be a floating point value between 0.0 and 1.0. * * In the hls() and hlsa() formats, the 'h' value (hue) is an angle between * 0 and 360.0 degrees; the 'l' and 's' values (luminance and saturation) are * percentage values in the range between 0% and 100%. The 'a' value, if specified, * can only be a floating point value between 0.0 and 1.0. * * Whitespace inside the definitions is ignored; no leading whitespace * is allowed. * * If the alpha component is not specified then it is assumed to be set to * be fully opaque. * * Return value: %TRUE if parsing succeeded, and %FALSE otherwise * * Since: 1.0 */ gboolean clutter_color_from_string (ClutterColor *color, const gchar *str) { PangoColor pango_color = { 0, }; g_return_val_if_fail (color != NULL, FALSE); g_return_val_if_fail (str != NULL, FALSE); if (strncmp (str, "rgb", 3) == 0) { gchar *s = (gchar *) str; gboolean res; if (strncmp (str, "rgba", 4) == 0) res = parse_rgba (color, s + 4, TRUE); else res = parse_rgba (color, s + 3, FALSE); return res; } if (strncmp (str, "hsl", 3) == 0) { gchar *s = (gchar *) str; gboolean res; if (strncmp (str, "hsla", 4) == 0) res = parse_hsla (color, s + 4, TRUE); else res = parse_hsla (color, s + 3, FALSE); return res; } /* if the string contains a color encoded using the hexadecimal * notations (#rrggbbaa or #rgba) we attempt a rough pass at * parsing the color ourselves, as we need the alpha channel that * Pango can't retrieve. */ if (str[0] == '#' && str[1] != '\0') { gsize length = strlen (str + 1); gint32 result; if (sscanf (str + 1, "%x", &result) == 1) { switch (length) { case 8: /* rrggbbaa */ color->red = (result >> 24) & 0xff; color->green = (result >> 16) & 0xff; color->blue = (result >> 8) & 0xff; color->alpha = result & 0xff; return TRUE; case 6: /* #rrggbb */ color->red = (result >> 16) & 0xff; color->green = (result >> 8) & 0xff; color->blue = result & 0xff; color->alpha = 0xff; return TRUE; case 4: /* #rgba */ color->red = ((result >> 12) & 0xf); color->green = ((result >> 8) & 0xf); color->blue = ((result >> 4) & 0xf); color->alpha = result & 0xf; color->red = (color->red << 4) | color->red; color->green = (color->green << 4) | color->green; color->blue = (color->blue << 4) | color->blue; color->alpha = (color->alpha << 4) | color->alpha; return TRUE; case 3: /* #rgb */ color->red = ((result >> 8) & 0xf); color->green = ((result >> 4) & 0xf); color->blue = result & 0xf; color->red = (color->red << 4) | color->red; color->green = (color->green << 4) | color->green; color->blue = (color->blue << 4) | color->blue; color->alpha = 0xff; return TRUE; default: return FALSE; } } }
void parse_thing_group(Tokenizer *tz) { thing_group_t *group = NULL; // Defaults rgba_t col; int size = -1; bool hanging = false; bool angle = true; // Check if group already exists string name = tz->get_token(); for (int a = 0; a < thing_types.size(); a++) { if (thing_types[a]->name == name) { group = thing_types[a]; break; } } // If it doesn't, create one if (!group) { group = new thing_group_t; group->name = name; thing_types.push_back(group); } tz->check_token("{"); // Parse the group string token = tz->get_token(); while (token != "}") { if (token == "default_colour") parse_rgba(tz, &col); if (token == "default_size") size = tz->get_integer(); if (token == "angle") angle = tz->get_bool(); if (token == "hanging") hanging = tz->get_bool(); if (token == "thing") { thing_type_t newtype; newtype.colour.set(col); newtype.radius = size; newtype.hanging = hanging; newtype.show_angle = angle; newtype.parse(tz); newtype.colour.a = 255; group->things.push_back(newtype); //console_print(parse_string("Added \"%s\" to group \"%s\"", newtype.name.c_str(), group->name.c_str())); } token = tz->get_token(); } }