コード例 #1
0
void josm_elemstyles_colorize_node(const style_t *style, node_t *node) {
  node->zoom_max = style->node.zoom_max;
  elemstyle_t *elemstyle = style->elemstyles;

  gboolean somematch = FALSE;
  while(elemstyle) {
    // Rule without conditions matches everything (should it?)
    gboolean match = elemstyle->condition ? TRUE : FALSE;

    // For rule with conditions, if any condition mismatches->rule mismatches
    elemstyle_condition_t *cond;
    for (cond = elemstyle->condition; cond && match; cond = cond->next) {
      if(cond->key) {
        const char *value = osm_node_get_value(node, (char*)cond->key);
        if(!value || (cond->value && strcasecmp(value, (char*)cond->value) != 0))
          match = FALSE;
      } else if(cond->value) {
        if(!osm_node_has_value(node, (char*)cond->value))
          match = FALSE;
      }
    }

    somematch = match ? TRUE : somematch;

    if(match && elemstyle->icon) {
      char *name = g_strjoin("/", "styles", style->icon.path_prefix,
				   elemstyle->icon->filename, NULL);

      /* free old icon if there's one present */
      if(node->icon_buf) {
	icon_free(style->iconP, node->icon_buf);
	node->icon_buf = NULL;
      }

      node->icon_buf = icon_load(style->iconP, name);
      g_free(name);

      if (elemstyle->icon->zoom_max > 0) {
        node->zoom_max = elemstyle->icon->zoom_max;
      }
    }

    elemstyle = elemstyle->next;
  }

  /* clear icon for node if not matched at least one rule and has an icon attached */
  if (!somematch && node->icon_buf) {
    icon_free(style->iconP, node->icon_buf);
    node->icon_buf = NULL;
  }
}
コード例 #2
0
void josm_elemstyles_colorize_world(const style_t *styles, osm_t *osm) {

  printf("preparing colors\n");

  /* colorize ways */
  way_t *way = osm->way;
  while(way) {
    josm_elemstyles_colorize_way(styles, way);
    way = way->next;
  }

  /* icons */
  node_t *node = osm->node;
  while(node) {
    /* remove all icon references that may still be there from */
    /* an old style */
    if(node->icon_buf) {
      icon_free(styles->iconP, node->icon_buf);
      node->icon_buf = NULL;
    }

    josm_elemstyles_colorize_node(styles, node);
    node = node->next;
  }
}
コード例 #3
0
ファイル: icons.c プロジェクト: khanhha/blender
/**
 * Remove icon and free data.
 */
void BKE_icon_delete(int icon_id)
{
	Icon *icon;

	if (!icon_id) return;  /* no icon defined for library object */

	icon = BLI_ghash_popkey(gIcons, SET_INT_IN_POINTER(icon_id), NULL);

	if (icon) {
		if (icon->type) {
			((ID *)(icon->obj))->icon_id = 0;
		}
		else {
			((PreviewImage *)(icon->obj))->icon_id = 0;
		}
		icon_free(icon);
	}
}
コード例 #4
0
/**
 * gupnp_device_info_get_icon_url:
 * @info: A #GUPnPDeviceInfo
 * @requested_mime_type: (allow-none) (transfer none): The requested file
 * format, or %NULL for any
 * @requested_depth: The requested color depth, or -1 for any
 * @requested_width: The requested width, or -1 for any
 * @requested_height: The requested height, or -1 for any
 * @prefer_bigger: %TRUE if a bigger, rather than a smaller icon should be
 * returned if no exact match could be found
 * @mime_type: (out) (allow-none): The location where to store the the format
 * of the returned icon, or %NULL. The returned string should be freed after
 * use
 * @depth: (out) (allow-none) :  The location where to store the depth of the
 * returned icon, or %NULL
 * @width: (out) (allow-none) : The location where to store the width of the
 * returned icon, or %NULL
 * @height: (out) (allow-none) : The location where to store the height of the
 * returned icon, or %NULL
 *
 * Get a URL pointing to the icon most closely matching the
 * given criteria, or %NULL. If @requested_mime_type is set, only icons with
 * this mime type will be returned. If @requested_depth is set, only icons with
 * this or lower depth will be returned. If @requested_width and/or
 * @requested_height are set, only icons that are this size or smaller are
 * returned, unless @prefer_bigger is set, in which case the next biggest icon
 * will be returned. The returned strings should be freed.
 *
 * Return value: (transfer full): a string, or %NULL.  g_free() after use.
 **/
char *
gupnp_device_info_get_icon_url (GUPnPDeviceInfo *info,
                                const char      *requested_mime_type,
                                int              requested_depth,
                                int              requested_width,
                                int              requested_height,
                                gboolean         prefer_bigger,
                                char           **mime_type,
                                int             *depth,
                                int             *width,
                                int             *height)
{
        GList *icons, *l;
        xmlNode *element;
        Icon *icon, *closest;
        char *ret;

        g_return_val_if_fail (GUPNP_IS_DEVICE_INFO (info), NULL);

        /* List available icons */
        icons = NULL;

        element = xml_util_get_element (info->priv->element,
                                        "iconList",
                                        NULL);
        if (!element)
                return NULL;

        for (element = element->children; element; element = element->next) {
                if (!strcmp ("icon", (char *) element->name)) {
                        gboolean mime_type_ok;

                        icon = icon_parse (info, element);

                        if (requested_mime_type) {
                                mime_type_ok =
                                        !strcmp (requested_mime_type,
                                                 (char *) icon->mime_type);
                        } else
                                mime_type_ok = TRUE;

                        if (requested_depth >= 0)
                                icon->weight = requested_depth - icon->depth;

                        /* Filter out icons with incorrect mime type or
                         * incorrect depth. */
                        if (mime_type_ok && icon->weight >= 0) {
                                if (requested_width >= 0) {
                                        if (prefer_bigger) {
                                                icon->weight +=
                                                        icon->width -
                                                        requested_width;
                                        } else {
                                                icon->weight +=
                                                        requested_width -
                                                        icon->width;
                                        }
                                }

                                if (requested_height >= 0) {
                                        if (prefer_bigger) {
                                                icon->weight +=
                                                        icon->height -
                                                        requested_height;
                                        } else {
                                                icon->weight +=
                                                        requested_height -
                                                        icon->height;
                                        }
                                }

                                icons = g_list_prepend (icons, icon);
                        } else
                                icon_free (icon);
                }
        }

        if (icons == NULL)
                return NULL;

        /* Find closest match */
        closest = NULL;
        for (l = icons; l; l = l->next) {
                icon = l->data;

                /* Look between icons with positive weight first */
                if (icon->weight >= 0) {
                        if (!closest || icon->weight < closest->weight)
                                closest = icon;
                }
        }

        if (!closest) {
                for (l = icons; l; l = l->next) {
                        icon = l->data;

                        /* No icons with positive weight, look at ones with
                         * negative weight */
                        if (!closest || icon->weight > closest->weight)
                                closest = icon;
                }
        }

        /* Fill in return values */
        if (closest) {
                icon = closest;

                if (mime_type) {
                        if (icon->mime_type) {
                                *mime_type = g_strdup
                                                ((char *) icon->mime_type);
                        } else
                                *mime_type = NULL;
                }

                if (depth)
                        *depth = icon->depth;
                if (width)
                        *width = icon->width;
                if (height)
                        *height = icon->height;

                if (icon->url) {
                        SoupURI *uri;

                        uri = soup_uri_new_with_base (info->priv->url_base,
                                                      (const char *) icon->url);
                        ret = soup_uri_to_string (uri, FALSE);
                        soup_uri_free (uri);
                } else
                        ret = NULL;
        } else {
                if (mime_type)
                        *mime_type = NULL;
                if (depth)
                        *depth = -1;
                if (width)
                        *width = -1;
                if (height)
                        *height = -1;

                ret = NULL;
        }

        /* Cleanup */
        while (icons) {
                icon_free (icons->data);
                icons = g_list_delete_link (icons, icons);
        }

        return ret;
}