示例#1
0
static void
bevel_right(uint8_t *p0, int w, int h)
{
  uint8_t *p = p0;
  int y;
  for(y = 0; y < h; y++) {
    p+= (w - 1) * GRAD_BPP;
    *p = GLW_MAX((int)*p - BEVEL_STRENGTH, 0);  p++;
    *p = GLW_MAX((int)*p - BEVEL_STRENGTH, 0);  p++;
    *p = GLW_MAX((int)*p - BEVEL_STRENGTH, 0);  p++;
  }
}
示例#2
0
static void
bevel_bottom(uint8_t *p0, int w, int h)
{
  int x;
  uint8_t *p = p0 + w * GRAD_BPP * (h - 1);

  for(x = 0; x < w; x++) {
    *p = GLW_MAX((int)*p - BEVEL_STRENGTH, 0);  p++;
    *p = GLW_MAX((int)*p - BEVEL_STRENGTH, 0);  p++;
    *p = GLW_MAX((int)*p - BEVEL_STRENGTH, 0);  p++;
  }
}
示例#3
0
static void
glw_image_layout_tesselated(glw_root_t *gr, glw_rctx_t *rc, glw_image_t *gi, 
			    glw_loadable_texture_t *glt)
{
  float tex[4][2];
  float vex[4][2];

  int x, y, i = 0;

  if(gr->gr_normalized_texture_coords) {
    tex[1][0] = 0.0f + (float)gi->gi_border_left  / glt->glt_xs;
    tex[2][0] = glt->glt_s - (float)gi->gi_border_right / glt->glt_xs;
    tex[0][0] = gi->gi_bitmap_flags & GLW_IMAGE_BORDER_LEFT ? 0.0f : tex[1][0];
    tex[3][0] = gi->gi_bitmap_flags & GLW_IMAGE_BORDER_RIGHT ? glt->glt_s : tex[2][0];

    tex[0][1] = 0.0f;
    tex[1][1] = 0.0f + (float)gi->gi_border_top    / glt->glt_ys;
    tex[2][1] = glt->glt_t - (float)gi->gi_border_bottom / glt->glt_ys;
    tex[3][1] = glt->glt_t;

  } else {

    tex[1][0] = gi->gi_border_left;
    tex[2][0] = glt->glt_xs - gi->gi_border_right;
    tex[0][0] = gi->gi_bitmap_flags & GLW_IMAGE_BORDER_LEFT  ? 0.0f : tex[1][0];
    tex[3][0] = gi->gi_bitmap_flags & GLW_IMAGE_BORDER_RIGHT ? glt->glt_xs : tex[2][0];

    tex[0][1] = 0.0f;
    tex[1][1] = gi->gi_border_top;
    tex[2][1] = glt->glt_ys - gi->gi_border_bottom;
    tex[3][1] = glt->glt_ys;
  }


  vex[0][0] = GLW_MIN(-1.0f + 2.0f * (gi->gi_margin_left)  / rc->rc_width, 0.0f);
  vex[1][0] = GLW_MIN(-1.0f + 2.0f * (gi->gi_border_left + gi->gi_margin_left)  / rc->rc_width, 0.0f);
  vex[2][0] = GLW_MAX( 1.0f - 2.0f * (gi->gi_border_right + gi->gi_margin_right) / rc->rc_width, 0.0f);
  vex[3][0] = GLW_MAX( 1.0f - 2.0f * (gi->gi_margin_right) / rc->rc_width, 0.0f);
    
  vex[0][1] = GLW_MAX( 1.0f - 2.0f * (gi->gi_margin_top)  / rc->rc_height, 0.0f);
  vex[1][1] = GLW_MAX( 1.0f - 2.0f * (gi->gi_border_top + gi->gi_margin_top)  / rc->rc_height, 0.0f);
  vex[2][1] = GLW_MIN(-1.0f + 2.0f * (gi->gi_border_bottom + gi->gi_margin_bottom) / rc->rc_height, 0.0f);
  vex[3][1] = GLW_MIN(-1.0f + 2.0f * (gi->gi_margin_bottom) / rc->rc_height, 0.0f);

  for(y = 0; y < 4; y++) {
    for(x = 0; x < 4; x++) {
      glw_renderer_vtx_pos(&gi->gi_gr, i, vex[x][0], vex[y][1], 0.0f);
      glw_renderer_vtx_st (&gi->gi_gr, i, tex[x][0], tex[y][1]);
      i++;
    }
  }
}
示例#4
0
文件: glw_image.c 项目: Hr-/showtime
static void
glw_image_layout_alpha_edges(glw_root_t *gr, glw_rctx_t *rc, glw_image_t *gi, 
			       glw_loadable_texture_t *glt)
{
  float tex[4][2];
  float vex[4][2];

  int x, y, i = 0;

  if(gr->gr_normalized_texture_coords) {
    tex[0][0] = 0.0f;
    tex[1][0] = 0.0f + (float)gi->gi_alpha_edge / glt->glt_xs;
    tex[2][0] = glt->glt_s - (float)gi->gi_alpha_edge / glt->glt_xs;
    tex[3][0] = glt->glt_s;

    tex[0][1] = 0.0f;
    tex[1][1] = 0.0f + (float)gi->gi_alpha_edge / glt->glt_ys;
    tex[2][1] = glt->glt_t - (float)gi->gi_alpha_edge / glt->glt_ys;
    tex[3][1] = glt->glt_t;
  } else {
    tex[0][0] = 0.0f;
    tex[1][0] = gi->gi_alpha_edge;
    tex[2][0] = glt->glt_xs - gi->gi_alpha_edge;
    tex[3][0] = glt->glt_xs;

    tex[0][1] = 0.0f;
    tex[1][1] = gi->gi_alpha_edge;
    tex[2][1] = glt->glt_ys - gi->gi_alpha_edge;
    tex[3][1] = glt->glt_ys;
  }

  vex[0][0] = -1.0f;
  vex[1][0] = GLW_MIN(-1.0f + 2.0f * gi->gi_alpha_edge / rc->rc_width, 0.0f);
  vex[2][0] = GLW_MAX( 1.0f - 2.0f * gi->gi_alpha_edge / rc->rc_width, 0.0f);
  vex[3][0] = 1.0f;
    
  vex[0][1] = 1.0f;
  vex[1][1] = GLW_MAX( 1.0f - 2.0f * gi->gi_alpha_edge / rc->rc_height, 0.0f);
  vex[2][1] = GLW_MIN(-1.0f + 2.0f * gi->gi_alpha_edge / rc->rc_height, 0.0f);
  vex[3][1] = -1.0f;

  for(y = 0; y < 4; y++) {
    for(x = 0; x < 4; x++) {
      glw_renderer_vtx_pos(&gi->gi_gr, i, vex[x][0], vex[y][1], 0.0f);
      glw_renderer_vtx_st (&gi->gi_gr, i, tex[x][0], tex[y][1]);
      glw_renderer_vtx_col(&gi->gi_gr, i, 1, 1, 1, alphaborder[x][y]);
      i++;
    }
  }
}
示例#5
0
static void
glw_freefloat_render(glw_t *w, const glw_rctx_t *rc)
{
  glw_freefloat_t *ff = (glw_freefloat_t *)w;
  glw_t *c;
  int i;
  float a;
  glw_rctx_t rc0;

  for(i = 0; i < ff->num_visible; i++) {
    if((c = ff->visible[i]) == NULL)
      continue;

    rc0 = *rc;
    a = (1 - fabs(-1 + (GLW_MAX(0, -0.1 + c->glw_parent_v * 2.1))));

    rc0.rc_alpha *= a;

    glw_Translatef(&rc0, 
		   c->glw_parent_x,
		   c->glw_parent_y,
		   -5 + c->glw_parent_v * 5);

    glw_Rotatef(&rc0, 
		-30 + c->glw_parent_v * 60,
		fabsf(sin(c->glw_parent_a)),
		fabsf(cos(c->glw_parent_a)),
		0.0);

    glw_render0(c, &rc0);
  }
}
示例#6
0
static void
update_value_delta(glw_slider_t *s, float d)
{
  if(s->p != NULL)
    prop_add_float(s->p, d * (s->max - s->min));
  else {
    s->value = GLW_MAX(s->min, GLW_MIN(s->max, s->value + d));
    if(s->bound_widget != NULL) {
      glw_scroll_t gs;
      gs.value = s->value;
      glw_signal0(s->bound_widget, GLW_SIGNAL_SCROLL, &gs);
    }
  }
}
示例#7
0
static void
update_value(glw_slider_t *s, float v, int how)
{
  v = GLW_MAX(0, GLW_MIN(1.0, v));

  if(s->p != NULL)
    prop_set_float_ex(s->p, NULL, v * (s->max - s->min) + s->min, how);
  else {
    s->value = v;
    if(s->bound_widget != NULL) {
      glw_scroll_t gs;
      gs.value = s->value;
      glw_signal0(s->bound_widget, GLW_SIGNAL_SCROLL, &gs);
    }
  }
}
示例#8
0
static void
update_value_delta(glw_slider_t *s, float d)
{
  if(s->p != NULL) {
    s->interpolate = 2;
    prop_add_float(s->p, d * (s->max - s->min));
  } else {
    s->value = GLW_MAX(s->min, GLW_MIN(s->max, s->value + d));
    s->interpolate = 1;
    if(s->bound_widget != NULL) {
      glw_scroll_t gs;
      gs.value = s->value;
      glw_signal0(s->bound_widget, GLW_SIGNAL_SCROLL, &gs);
    }
    glw_need_refresh(s->w.glw_root, 0);
  }
}
示例#9
0
void
glw_scroll_handle_scroll(glw_scroll_control_t *gsc, glw_t *w, glw_scroll_t *gs)
{
  int top = GLW_MAX(gs->value * (gsc->total_size - gsc->page_size
                                 + gsc->scroll_threshold_post), 0);
  gsc->target_pos = top;
  glw_schedule_refresh(w->glw_root, 0);

  if(gsc->chase_focus == 0)
    return;

  glw_t *c = w->glw_class->gc_find_visible_child(w);
  if(c == NULL)
    return;

  if(glw_is_focused(w)) {
    glw_focus_set(w->glw_root, c, GLW_FOCUS_SET_SUGGESTED, "Scroll");
  } else {
    w->glw_focused = c;
    glw_signal0(w, GLW_SIGNAL_FOCUS_CHILD_INTERACTIVE, c);
  }
}
示例#10
0
void
glw_scroll_update_metrics(glw_scroll_control_t *gsc, glw_t *w)
{
  float v;
  int do_update = 0;

  w->glw_flags &= ~GLW_UPDATE_METRICS;

  v = GLW_MIN(1.0f, (float)gsc->page_size / gsc->total_size);

  if(v != gsc->metrics.knob_size) {
    do_update = 1;
    gsc->metrics.knob_size = v;
  }
  
  v = GLW_MAX(0, (float)gsc->target_pos / (gsc->total_size - gsc->page_size + gsc->scroll_threshold_post));

  if(v != gsc->metrics.position) {
    do_update = 1;
    gsc->metrics.position = v;
  }
  
  if(!do_update)
    return;

  if(gsc->total_size > gsc->page_size && !(w->glw_flags & GLW_CAN_SCROLL)) {
    w->glw_flags |= GLW_CAN_SCROLL;
    glw_signal0(w, GLW_SIGNAL_CAN_SCROLL_CHANGED, NULL);
    
  } else if(gsc->total_size <= gsc->page_size &&
	    w->glw_flags & GLW_CAN_SCROLL) {
    w->glw_flags &= ~GLW_CAN_SCROLL;
    glw_signal0(w, GLW_SIGNAL_CAN_SCROLL_CHANGED, NULL);
  }

  glw_signal0(w, GLW_SIGNAL_SLIDER_METRICS, &gsc->metrics);
}
示例#11
0
static void
prop_callback(void *opaque, prop_event_t event, ...)
{
  glw_slider_t *sl = opaque;
  glw_root_t *gr;
  float v;
  prop_t *p;
  int how = 0;
  int grabbed;

  if(sl == NULL)
    return;

  gr = sl->w.glw_root;
  va_list ap;
  va_start(ap, event);
  grabbed = gr->gr_pointer_grab == &sl->w;

  switch(event) {
  case PROP_SET_VOID:
    if(grabbed)
      gr->gr_pointer_grab = NULL;

    v = 0;
    p = va_arg(ap, prop_t *);
    break;

  case PROP_SET_FLOAT:
    v = va_arg(ap, double);
    p = va_arg(ap, prop_t *);
    how = va_arg(ap, int);
    break;

  case PROP_SET_INT:
    v = va_arg(ap, int);
    p = va_arg(ap, prop_t *);
    break;

  default:
    return;
  }
  prop_ref_dec(sl->p);
  sl->p = prop_ref_inc(p);
  
  switch(how) {
  case PROP_SET_NORMAL:
    if(sl->tentative_only)
      return;
    break;
  case PROP_SET_TENTATIVE:
    sl->tentative_only = 1;
    break;
  case PROP_SET_COMMIT:
    sl->tentative_only = 0;
    break;
  }

  if(sl->max - sl->min == 0)
    return;

  v = GLW_RESCALE(v, sl->min, sl->max);
  sl->value = GLW_MAX(0, GLW_MIN(1.0, v));
  if(sl->interpolate)
    sl->interpolate--;
}
示例#12
0
static void
glw_slideshow_layout(glw_t *w, const glw_rctx_t *rc)
{
  glw_slideshow_t *s = (glw_slideshow_t *)w;
  glw_t *c, *p, *n;
  float delta;

  glw_reset_screensaver(w->glw_root);

  delta = s->w.glw_root->gr_frameduration / (1000000.0 * s->transition_time);
  if(s->time == 0) {
    s->displaytime = INT32_MAX;
  } else {
    s->displaytime = 1000000 * s->time / s->w.glw_root->gr_frameduration;
  }

    
  if((c = s->w.glw_focused) == NULL) {
    c = s->w.glw_focused = glw_first_widget(&s->w);
    if(c)
      glw_copy_constraints(&s->w, c);
  }
  if(c == NULL)
    return;

  if(s->timer >= s->displaytime) {
    c = glw_next_widget(c);
    if(c == NULL)
      c = glw_first_widget(&s->w);
    s->timer = 0;
    if(c != NULL) {
      glw_focus_open_path_close_all_other(c);
      glw_copy_constraints(&s->w, c);
    }
  }
  
  if(!s->hold)
    s->timer++;

  glw_layout0(c, rc);
  c->glw_parent_alpha = GLW_MIN(c->glw_parent_alpha + delta, 1.0f);

  /**
   * Keep previous and next images 'hot' (ie, loaded into texture memory)
   */
  p = glw_prev_widget(c);
  if(p == NULL)
    p = glw_last_widget(&s->w);
  if(p != NULL && p != c) {
    p->glw_parent_alpha = GLW_MAX(p->glw_parent_alpha - delta, 0.0f);
    glw_layout0(p, rc);
  }

  n = glw_next_widget(c);
  if(n == NULL)
    n = glw_first_widget(&s->w);
  if(n != NULL && n != c) {
    n->glw_parent_alpha = GLW_MAX(n->glw_parent_alpha - delta, 0.0f);
    glw_layout0(n, rc);
  }
}
示例#13
0
static void
glw_image_layout_tesselated(glw_root_t *gr, glw_rctx_t *rc, glw_image_t *gi, 
			    glw_loadable_texture_t *glt)
{
  float tex[4][2];
  float vex[4][2];

  int x, y, i = 0, BL, BR;

  if(gi->w.glw_flags2 & GLW2_AUTOMARGIN) {

    gi->gi_automargin_left = 0;
    gi->gi_automargin_top = 0;
    gi->gi_automargin_right = 0;
    gi->gi_automargin_bottom = 0;
    
    glw_t *c = TAILQ_FIRST(&gi->w.glw_childs);

    if(c != NULL && (c->glw_flags & (GLW_CONSTRAINT_X | GLW_CONSTRAINT_Y)) ==
		     (GLW_CONSTRAINT_X | GLW_CONSTRAINT_Y)) {

      int hspill = rc->rc_width - c->glw_req_size_x - 
	gi->gi_box_left - gi->gi_box_right;

      if(hspill > 0) {
	gi->gi_automargin_left = hspill / 2 + (hspill & 1);
	gi->gi_automargin_right = hspill / 2;
      }
      
      int vspill = rc->rc_height - c->glw_req_size_y -
	gi->gi_box_top - gi->gi_box_bottom;

      if(vspill > 0) {
	gi->gi_automargin_top = vspill / 2 + (vspill & 1);
	gi->gi_automargin_bottom = vspill / 2;
      }

    } else if(c != NULL && c->glw_flags & GLW_CONSTRAINT_W &&
	      c->glw_req_weight < 0) {
      float aspect = -c->glw_req_weight;

      float cw = rc->rc_width - gi->gi_box_left - gi->gi_box_right;
      float ch = rc->rc_height - gi->gi_box_top - gi->gi_box_bottom;

      float myaspect = cw / ch;

      if(myaspect > aspect) {
	// We are wider than our child wants
	
	int cwidth = ch * aspect;
	int hspill = cw - cwidth;
      
	if(hspill > 0) {
	  gi->gi_automargin_left = hspill / 2 + (hspill & 1);
	  gi->gi_automargin_right = hspill / 2;
	}
      } else {
	int cheight = cw / aspect;
	int vspill = ch - cheight;

	if(vspill > 0) {
	  gi->gi_automargin_top = vspill / 2 + (vspill & 1);
	  gi->gi_automargin_bottom = vspill / 2;
	}
      }
    } else if(gi->gi_child_aspect > 0) {
      
      int px = rc->rc_height * gi->gi_child_aspect;
      int hspill = rc->rc_width - px - gi->gi_box_left - gi->gi_box_right;
      
      if(hspill > 0) {
	gi->gi_automargin_left = hspill / 2 + (hspill & 1);
	gi->gi_automargin_right = hspill / 2;
      }

    }
    if(gi->w.glw_flags & GLW_DEBUG)
      printf("Automargin %d,%d,%d,%d\n",
	     gi->gi_automargin_left,
	     gi->gi_automargin_top,
	     gi->gi_automargin_right,
	     gi->gi_automargin_bottom);


    update_box(gi);
  }

  if(gr->gr_normalized_texture_coords) {

    tex[1][0] = 0.0f + (float)gi->gi_border_left  / glt->glt_xs;
    tex[2][0] = glt->glt_s - (float)gi->gi_border_right / glt->glt_xs;
    tex[0][0] = gi->gi_bitmap_flags & GLW_IMAGE_BORDER_LEFT ? 0.0f : tex[1][0];
    tex[3][0] = gi->gi_bitmap_flags & GLW_IMAGE_BORDER_RIGHT ? glt->glt_s : tex[2][0];

    tex[0][1] = 0.0f;
    tex[1][1] = 0.0f + (float)gi->gi_border_top    / glt->glt_ys;
    tex[2][1] = glt->glt_t - (float)gi->gi_border_bottom / glt->glt_ys;
    tex[3][1] = glt->glt_t;

  } else {

    tex[1][0] = gi->gi_border_left;
    tex[2][0] = glt->glt_xs - gi->gi_border_right;
    tex[0][0] = gi->gi_bitmap_flags & GLW_IMAGE_BORDER_LEFT  ? 0.0f : tex[1][0];
    tex[3][0] = gi->gi_bitmap_flags & GLW_IMAGE_BORDER_RIGHT ? glt->glt_xs : tex[2][0];

    tex[0][1] = 0.0f;
    tex[1][1] = gi->gi_border_top;
    tex[2][1] = glt->glt_ys - gi->gi_border_bottom;
    tex[3][1] = glt->glt_ys;
  }

  if(gi->gi_bitmap_flags & GLW_IMAGE_ASPECT_FIXED_BORDERS) {
    BL = rc->rc_height * gi->gi_border_left / glt->glt_ys;
    BR = rc->rc_height * gi->gi_border_right / glt->glt_ys;
    gi->gi_border_left_afix = BL;
    gi->gi_border_right_afix = BR;
    update_box(gi);
  } else {
    BL = gi->gi_border_left;
    BR = gi->gi_border_right;
  }


  vex[0][0] = GLW_MIN(-1.0f + 2.0f * (gi->gi_margin_left + gi->gi_automargin_left)  / rc->rc_width, 0.0f);
  vex[1][0] = GLW_MIN(-1.0f + 2.0f * (BL + gi->gi_margin_left + gi->gi_automargin_left)  / rc->rc_width, 0.0f);
  vex[2][0] = GLW_MAX( 1.0f - 2.0f * (BR + gi->gi_margin_right + gi->gi_automargin_right) / rc->rc_width, 0.0f);
  vex[3][0] = GLW_MAX( 1.0f - 2.0f * (gi->gi_margin_right + gi->gi_automargin_right) / rc->rc_width, 0.0f);
    
  vex[0][1] = GLW_MAX( 1.0f - 2.0f * (gi->gi_margin_top + gi->gi_automargin_top)  / rc->rc_height, 0.0f);
  vex[1][1] = GLW_MAX( 1.0f - 2.0f * (gi->gi_border_top + gi->gi_margin_top + gi->gi_automargin_top)  / rc->rc_height, 0.0f);
  vex[2][1] = GLW_MIN(-1.0f + 2.0f * (gi->gi_border_bottom + gi->gi_margin_bottom + gi->gi_automargin_bottom) / rc->rc_height, 0.0f);
  vex[3][1] = GLW_MIN(-1.0f + 2.0f * (gi->gi_margin_bottom + gi->gi_automargin_bottom) / rc->rc_height, 0.0f);

  for(y = 0; y < 4; y++) {
    for(x = 0; x < 4; x++) {
      glw_renderer_vtx_pos(&gi->gi_gr, i, vex[x][0], vex[y][1], 0.0f);
      glw_renderer_vtx_st (&gi->gi_gr, i, tex[x][0], tex[y][1]);
      i++;
    }
  }
}
示例#14
0
static void
glw_slideshow_layout(glw_t *w, const glw_rctx_t *rc)
{
  glw_root_t *gr = w->glw_root;
  glw_slideshow_t *s = (glw_slideshow_t *)w;
  glw_t *c, *p, *n;
  float delta;
  int r = 0;

  glw_reset_screensaver(w->glw_root);

  delta = s->w.glw_root->gr_frameduration / (float)s->transition_time;

  if((c = s->w.glw_focused) == NULL) {
    c = s->w.glw_focused = glw_first_widget(&s->w);
    if(c)
      glw_copy_constraints(&s->w, c);
  }

  if(c == NULL)
    return;

  glw_schedule_refresh(gr, s->deadline);

  if(s->deadline <= gr->gr_frame_start) {
    s->deadline = gr->gr_frame_start + s->display_time;

    c = glw_next_widget(c);
    if(c == NULL)
      c = glw_first_widget(&s->w);
    if(c != NULL) {
      glw_focus_open_path_close_all_other(c);
      glw_copy_constraints(&s->w, c);
    }
  }

  glw_layout0(c, rc);
  r |= update_parent_alpha(c, GLW_MIN(c->glw_parent_alpha + delta, 1.0f));

  /**
   * Keep previous and next images 'hot' (ie, loaded into texture memory)
   */
  p = glw_prev_widget(c);
  if(p == NULL)
    p = glw_last_widget(&s->w, 0);
  if(p != NULL && p != c) {
    r |= update_parent_alpha(p, GLW_MAX(p->glw_parent_alpha - delta, 0.0f));
    glw_layout0(p, rc);
  }

  n = glw_next_widget(c);
  if(n == NULL)
    n = glw_first_widget(&s->w);
  if(n != NULL && n != c) {
    r |= update_parent_alpha(n, GLW_MAX(n->glw_parent_alpha - delta, 0.0f));
    glw_layout0(n, rc);
  }

  if(r)
    glw_need_refresh(w->glw_root, 0);
}