Beispiel #1
0
static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, char *str, size_t len)
{
	size_t ofs = 0;

	str[0] = 0;
	if (ima == NULL)
		return;

	if (ibuf == NULL) {
		ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Can't Load Image"), len - ofs);
	}
	else {
		if (ima->source == IMA_SRC_MOVIE) {
			ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Movie"), len - ofs);
			if (ima->anim)
				ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(" %d frs"),
				                    IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN));
		}
		else {
			ofs += BLI_strncpy_rlen(str, IFACE_("Image"), len - ofs);
		}

		ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(": size %d x %d,"), ibuf->x, ibuf->y);

		if (ibuf->rect_float) {
			if (ibuf->channels != 4) {
				ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_("%d float channel(s)"), ibuf->channels);
			}
			else if (ibuf->planes == R_IMF_PLANES_RGBA)
				ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA float"), len - ofs);
			else
				ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB float"), len - ofs);
		}
		else {
			if (ibuf->planes == R_IMF_PLANES_RGBA)
				ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGBA byte"), len - ofs);
			else
				ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" RGB byte"), len - ofs);
		}
		if (ibuf->zbuf || ibuf->zbuf_float)
			ofs += BLI_strncpy_rlen(str + ofs, IFACE_(" + Z"), len - ofs);

		if (ima->source == IMA_SRC_SEQUENCE) {
			const char *file = BLI_last_slash(ibuf->name);
			if (file == NULL)
				file = ibuf->name;
			else
				file++;
			ofs += BLI_snprintf(str + ofs, len - ofs, ", %s", file);
		}
	}

	/* the frame number, even if we cant */
	if (ima->source == IMA_SRC_SEQUENCE) {
		/* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
		const int framenr = BKE_image_user_frame_get(iuser, CFRA, 0, NULL);
		ofs += BLI_snprintf(str + ofs, len - ofs, IFACE_(", Frame: %d"), framenr);
	}
}
Beispiel #2
0
int WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, int len)
{
	char buf[128];

	buf[0] = 0;

	if (kmi->shift == KM_ANY &&
	    kmi->ctrl == KM_ANY &&
	    kmi->alt == KM_ANY &&
	    kmi->oskey == KM_ANY)
	{
		strcat(buf, "Any ");
	}
	else {
		if (kmi->shift)
			strcat(buf, "Shift ");

		if (kmi->ctrl)
			strcat(buf, "Ctrl ");

		if (kmi->alt)
			strcat(buf, "Alt ");

		if (kmi->oskey)
			strcat(buf, "Cmd ");
	}
		
	if (kmi->keymodifier) {
		strcat(buf, WM_key_event_string(kmi->keymodifier));
		strcat(buf, " ");
	}

	strcat(buf, WM_key_event_string(kmi->type));
	return BLI_strncpy_rlen(str, buf, len);
}
Beispiel #3
0
static bool get_thumb_dir(char *dir, ThumbSize size)
{
	char *s = dir;
	const char *subdir;
#ifdef WIN32
	wchar_t dir_16[MAX_PATH];
	/* yes, applications shouldn't store data there, but so does GIMP :)*/
	SHGetSpecialFolderPathW(0, dir_16, CSIDL_PROFILE, 0);
	conv_utf_16_to_8(dir_16, dir, FILE_MAX);
	s += strlen(dir);
#else
#if defined(USE_FREEDESKTOP)
	const char *home_cache = getenv("XDG_CACHE_HOME");
	const char *home = home_cache ? home_cache : getenv("HOME");
#else
	const char *home = getenv("HOME");
#endif
	if (!home) return 0;
	s += BLI_strncpy_rlen(s, home, FILE_MAX);

#ifdef USE_FREEDESKTOP
	if (!home_cache) {
		s += BLI_strncpy_rlen(s, "/.cache", FILE_MAX - (s - dir));
	}
#endif
#endif
	switch (size) {
		case THB_NORMAL:
			subdir = "/" THUMBNAILS "/normal/";
			break;
		case THB_LARGE:
			subdir = "/" THUMBNAILS "/large/";
			break;
		case THB_FAIL:
			subdir = "/" THUMBNAILS "/fail/blender/";
			break;
		default:
			return 0; /* unknown size */
	}

	s += BLI_strncpy_rlen(s, subdir, FILE_MAX - (s - dir));
	(void)s;

	return 1;
}
Beispiel #4
0
/* add the relevant text to the cache of text-strings to draw in pixelspace */
static void nla_draw_strip_text(AnimData *adt,
                                NlaTrack *nlt,
                                NlaStrip *strip,
                                int index,
                                View2D *v2d,
                                float xminc,
                                float xmaxc,
                                float yminc,
                                float ymaxc)
{
  const bool non_solo = ((adt && (adt->flag & ADT_NLA_SOLO_TRACK)) &&
                         (nlt->flag & NLATRACK_SOLO) == 0);
  char str[256];
  size_t str_len;
  char col[4];

  /* just print the name and the range */
  if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
    str_len = BLI_snprintf_rlen(str, sizeof(str), "%d) Temp-Meta", index);
  }
  else {
    str_len = BLI_strncpy_rlen(str, strip->name, sizeof(str));
  }

  /* set text color - if colors (see above) are light, draw black text, otherwise draw white */
  if (strip->flag & (NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT | NLASTRIP_FLAG_TWEAKUSER)) {
    col[0] = col[1] = col[2] = 0;
  }
  else {
    col[0] = col[1] = col[2] = 255;
  }

  /* text opacity depends on whether if there's a solo'd track, this isn't it */
  if (non_solo == 0) {
    col[3] = 255;
  }
  else {
    col[3] = 128;
  }

  /* set bounding-box for text
   * - padding of 2 'units' on either side
   */
  /* TODO: make this centered? */
  rctf rect = {
      .xmin = xminc,
      .ymin = yminc,
      .xmax = xmaxc,
      .ymax = ymaxc,
  };

  /* add this string to the cache of texts to draw */
  UI_view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
}
bool IMB_thumb_load_font_get_hash(char *r_hash)
{
	char buf[1024];
	char *str = buf;
	size_t len = 0;

	int draw_str_lines = ARRAY_SIZE(thumb_str);
	int i;

	unsigned char digest[16];

	len += BLI_strncpy_rlen(str + len, THUMB_DEFAULT_HASH, sizeof(buf) - len);

	for (i = 0; (i < draw_str_lines) && (len < sizeof(buf)); i++) {
		len += BLI_strncpy_rlen(str + len, BLT_translate_do(BLT_I18NCONTEXT_DEFAULT, thumb_str[i]), sizeof(buf) - len);
	}

	BLI_hash_md5_buffer(str, len, digest);
	r_hash[0] = '\0';
	BLI_hash_md5_to_hexdigest(digest, r_hash);

	return true;
}
Beispiel #6
0
/* add the relevant text to the cache of text-strings to draw in pixelspace */
static void nla_draw_strip_text(AnimData *adt, NlaTrack *nlt, NlaStrip *strip, int index, View2D *v2d, float yminc, float ymaxc)
{
	short notSolo = ((adt && (adt->flag & ADT_NLA_SOLO_TRACK)) && (nlt->flag & NLATRACK_SOLO) == 0);
	char str[256];
	size_t str_len;
	char col[4];
	float xofs;
	rctf rect;
	
	/* just print the name and the range */
	if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
		str_len = BLI_snprintf(str, sizeof(str), "%d) Temp-Meta", index);
	}
	else {
		str_len = BLI_strncpy_rlen(str, strip->name, sizeof(str));
	}
	
	/* set text color - if colors (see above) are light, draw black text, otherwise draw white */
	if (strip->flag & (NLASTRIP_FLAG_ACTIVE | NLASTRIP_FLAG_SELECT | NLASTRIP_FLAG_TWEAKUSER)) {
		col[0] = col[1] = col[2] = 0;
	}
	else {
		col[0] = col[1] = col[2] = 255;
	}
	
	/* text opacity depends on whether if there's a solo'd track, this isn't it */
	if (notSolo == 0)
		col[3] = 255;
	else
		col[3] = 128;
	
	/* determine the amount of padding required - cannot be constant otherwise looks weird in some cases */
	if ((strip->end - strip->start) <= 5.0f)
		xofs = 0.5f;
	else
		xofs = 1.0f;
	
	/* set bounding-box for text 
	 *	- padding of 2 'units' on either side
	 */
	// TODO: make this centered?
	rect.xmin = strip->start + xofs;
	rect.ymin = yminc;
	rect.xmax = strip->end - xofs;
	rect.ymax = ymaxc;
	
	/* add this string to the cache of texts to draw */
	UI_view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
}
Beispiel #7
0
static void unpack_generate_paths(
        const char *name, ID *id, char *r_abspath, char *r_relpath, size_t abspathlen, size_t relpathlen)
{
	char tempname[FILE_MAX];
	char tempdir[FILE_MAXDIR];

	BLI_split_dirfile(name, tempdir, tempname, sizeof(tempdir), sizeof(tempname));

	if (tempname[0] == '\0') {
		/* Note: we do not have any real way to re-create extension out of data... */
		BLI_strncpy(tempname, id->name + 2, sizeof(tempname));
		printf("%s\n", tempname);
		BLI_filename_make_safe(tempname);
		printf("%s\n", tempname);
	}

	if (tempdir[0] == '\0') {
		/* Fallback to relative dir. */
		BLI_strncpy(tempdir, "//", sizeof(tempdir));
	}

	switch (GS(id->name)) {
		case ID_VF:
			BLI_snprintf(r_relpath, relpathlen, "//fonts/%s", tempname);
			break;
		case ID_SO:
			BLI_snprintf(r_relpath, relpathlen, "//sounds/%s", tempname);
			break;
		case ID_IM:
			BLI_snprintf(r_relpath, relpathlen, "//textures/%s", tempname);
			break;
		default:
			break;
	}

	{
		size_t len = BLI_strncpy_rlen(r_abspath, tempdir, abspathlen);
		BLI_strncpy(r_abspath + len, tempname, abspathlen - len);
	}
}
Beispiel #8
0
/* 45µm --> 45um */
void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int system, int type)
{
	bUnitCollection *usys = unit_get_system(system, type);

	bUnitDef *unit;
	bUnitDef *unit_def = unit_default(usys);

	/* find and substitute all units */
	for (unit = usys->units; unit->name; unit++) {
		if (len_max > 0 && (unit->name_alt || unit == unit_def)) {
			const char *found = unit_find_str(orig_str, unit->name_short);
			if (found) {
				int offset = (int)(found - orig_str);
				int len_name = 0;

				/* copy everything before the unit */
				offset = (offset < len_max ? offset : len_max);
				strncpy(str, orig_str, offset);

				str += offset;
				orig_str += offset + strlen(unit->name_short);
				len_max -= offset;

				/* print the alt_name */
				if (unit->name_alt)
					len_name = BLI_strncpy_rlen(str, unit->name_alt, len_max);
				else
					len_name = 0;

				len_name = (len_name < len_max ? len_name : len_max);
				str += len_name;
				len_max -= len_name;
			}
		}
	}

	/* finally copy the rest of the string */
	strncpy(str, orig_str, len_max);
}