Beispiel #1
0
float file_font_pointsize(void)
{
#if 0
	float s;
	char tmp[2] = "X";
	uiStyle *style = UI_style_get();
	UI_fontstyle_set(&style->widget);
	s = BLF_height(style->widget.uifont_id, tmp);
	return style->widget.points;
#else
	uiStyle *style = UI_style_get();
	UI_fontstyle_set(&style->widget);
	return style->widget.points * UI_DPI_FAC;
#endif
}
Beispiel #2
0
static void file_draw_string(int sx, int sy, const char *string, float width, int height, short align)
{
	uiStyle *style;
	uiFontStyle fs;
	rcti rect;
	char fname[FILE_MAXFILE];

	if (string[0] == '\0') {
		return;
	}

	style = UI_style_get();
	fs = style->widgetlabel;

	fs.align = align;

	BLI_strncpy(fname, string, FILE_MAXFILE);
	UI_text_clip_middle_ex(&fs, fname, width, UI_DPI_ICON_SIZE, sizeof(fname), '\0');

	/* no text clipping needed, UI_fontstyle_draw does it but is a bit too strict (for buttons it works) */
	rect.xmin = sx;
	rect.xmax = (int)(sx + ceil(width + 5.0f / UI_DPI_FAC));
	rect.ymin = sy - height;
	rect.ymax = sy;

	UI_fontstyle_draw(&fs, &rect, fname);
}
Beispiel #3
0
float file_string_width(const char *str)
{
	uiStyle *style = UI_style_get();
	float width;

	UI_fontstyle_set(&style->widget);
	if (style->widget.kerning == 1) {  /* for BLF_width */
		BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
	}

	width = BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);

	if (style->widget.kerning == 1) {
		BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT);
	}

	return width;
}
/* for drawing, scaled with DPI setting */
uiStyle *UI_style_get_dpi(void)
{
	uiStyle *style = UI_style_get();
	static uiStyle _style;
	
	_style = *style;
	
	_style.paneltitle.shadx = (short)(UI_DPI_FAC * _style.paneltitle.shadx);
	_style.paneltitle.shady = (short)(UI_DPI_FAC * _style.paneltitle.shady);
	_style.grouplabel.shadx = (short)(UI_DPI_FAC * _style.grouplabel.shadx);
	_style.grouplabel.shady = (short)(UI_DPI_FAC * _style.grouplabel.shady);
	_style.widgetlabel.shadx = (short)(UI_DPI_FAC * _style.widgetlabel.shadx);
	_style.widgetlabel.shady = (short)(UI_DPI_FAC * _style.widgetlabel.shady);
	
	_style.columnspace = (short)(UI_DPI_FAC * _style.columnspace);
	_style.templatespace = (short)(UI_DPI_FAC * _style.templatespace);
	_style.boxspace = (short)(UI_DPI_FAC * _style.boxspace);
	_style.buttonspacex = (short)(UI_DPI_FAC * _style.buttonspacex);
	_style.buttonspacey = (short)(UI_DPI_FAC * _style.buttonspacey);
	_style.panelspace = (short)(UI_DPI_FAC * _style.panelspace);
	_style.panelouter = (short)(UI_DPI_FAC * _style.panelouter);
	
	return &_style;
}
Beispiel #5
0
void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar)
{
  ScrArea *sa = CTX_wm_area(C);
  SpaceClip *sc = CTX_wm_space_clip(C);
  View2D *v2d = &ar->v2d;
  MovieClip *clip = ED_space_clip_get_clip(sc);
  uiStyle *style = UI_style_get();
  int fontid = style->widget.uifont_id;

  if (!clip) {
    return;
  }

  MovieTracking *tracking = &clip->tracking;
  MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
  int height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT);

  if (height > BLI_rcti_size_y(&v2d->mask)) {
    /* don't use totrect set, as the width stays the same
     * (NOTE: this is ok here, the configuration is pretty straightforward)
     */
    v2d->tot.ymin = (float)(-height);
  }

  /* need to do a view-sync here, so that the keys area doesn't jump around
   * (it must copy this) */
  UI_view2d_sync(NULL, sa, v2d, V2D_LOCK_COPY);

  /* loop through channels, and set up drawing depending on their type
   * first pass: just the standard GL-drawing for backdrop + text
   */
  float y = (float)CHANNEL_FIRST;

  GPUVertFormat *format = immVertexFormat();
  uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);

  immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);

  MovieTrackingDopesheetChannel *channel;
  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
    float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
    float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);

    /* check if visible */
    if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
        IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
      MovieTrackingTrack *track = channel->track;
      float color[3];
      track_channel_color(track, NULL, color);
      immUniformColor3fv(color);

      immRectf(pos,
               v2d->cur.xmin,
               (float)y - CHANNEL_HEIGHT_HALF,
               v2d->cur.xmax + EXTRA_SCROLL_PAD,
               (float)y + CHANNEL_HEIGHT_HALF);
    }

    /* adjust y-position for next one */
    y -= CHANNEL_STEP;
  }
  immUnbindProgram();

  /* second pass: text */
  y = (float)CHANNEL_FIRST;

  BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);

  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
    float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
    float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);

    /* check if visible */
    if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
        IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
      MovieTrackingTrack *track = channel->track;
      bool sel = (track->flag & TRACK_DOPE_SEL) != 0;

      UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT);

      float font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
      BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f);
      BLF_draw(fontid, channel->name, strlen(channel->name));
    }

    /* adjust y-position for next one */
    y -= CHANNEL_STEP;
  }

  /* third pass: widgets */
  uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
  y = (float)CHANNEL_FIRST;

  /* get RNA properties (once) */
  PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock");
  BLI_assert(chan_prop_lock);

  GPU_blend(true);
  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
    float yminc = (float)(y - CHANNEL_HEIGHT_HALF);
    float ymaxc = (float)(y + CHANNEL_HEIGHT_HALF);

    /* check if visible */
    if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
        IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax)) {
      MovieTrackingTrack *track = channel->track;
      const int icon = (track->flag & TRACK_LOCKED) ? ICON_LOCKED : ICON_UNLOCKED;
      PointerRNA ptr;

      RNA_pointer_create(&clip->id, &RNA_MovieTrackingTrack, track, &ptr);

      UI_block_emboss_set(block, UI_EMBOSS_NONE);
      uiDefIconButR_prop(block,
                         UI_BTYPE_ICON_TOGGLE,
                         1,
                         icon,
                         v2d->cur.xmax - UI_UNIT_X - CHANNEL_PAD,
                         y - UI_UNIT_Y / 2.0f,
                         UI_UNIT_X,
                         UI_UNIT_Y,
                         &ptr,
                         chan_prop_lock,
                         0,
                         0,
                         0,
                         0,
                         0,
                         NULL);
      UI_block_emboss_set(block, UI_EMBOSS);
    }

    /* adjust y-position for next one */
    y -= CHANNEL_STEP;
  }
  GPU_blend(false);

  UI_block_end(C, block);
  UI_block_draw(C, block);
}
Beispiel #6
0
float file_string_width(const char *str)
{
	uiStyle *style = UI_style_get();
	UI_fontstyle_set(&style->widget);
	return BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
}