Beispiel #1
0
Datei: ombre.c Projekt: fave-r/RT
int		ombre(t_obj *obj, t_eye *eye, t_light l, t_spot *cur_spot)
{
  t_obj		*c_obj;
  t_vec3	*inter;
  t_vec3	*vec_light;

  c_obj = obj->next;
  inter = xmalloc(sizeof(*inter));
  inter = inter_obj(inter, eye, l.k2);
  vec_light = to_light_(inter, cur_spot);
  while (c_obj != NULL)
    {
      if (c_obj != l.clos_obj
	  && my_strcmp(l.clos_obj->info->type, "CONE") != 0)
        {
	  translate_pos(inter, c_obj->pos);
	  l.k2 = tab[find_type(c_obj)].inter(inter, vec_light, c_obj->info->R);
	  translate_pos_inv(inter, c_obj->pos);
          if (l.k2 > ZERO && l.k2 < 1 + ZERO)
	    return (free_inter(1, inter, vec_light));
        }
      c_obj = c_obj->next;
    }
  return (free_inter(0, inter, vec_light));
}
Beispiel #2
0
static pos
translate_pos(int x, int y)
{
  return (pos){
    .x = floorf((x - PADDING) / (float)font_width ),
    .y = floorf((y - PADDING) / (float)font_height), 
  };
}

static pos
get_mouse_pos(LPARAM lp)
{
  return translate_pos(GET_X_LPARAM(lp), GET_Y_LPARAM(lp));  
}

static mouse_button clicked_button;
static pos last_pos;

void
win_mouse_click(mouse_button b, LPARAM lp)
{
  static mouse_button last_button;
  static uint last_time, count;
  static pos last_click_pos;

  win_show_mouse();
  mod_keys mods = get_mods();
  pos p = get_mouse_pos(lp);
  
  if (clicked_button) {
    term_mouse_release(b, mods, p);
    clicked_button = 0;
  }
  
  uint t = GetMessageTime();
  if (b != last_button ||
      p.x != last_click_pos.x || p.y != last_click_pos.y ||
      t - last_time > GetDoubleClickTime() || ++count > 3)
    count = 1;
  term_mouse_click(b, mods, p, count);
  last_pos = last_click_pos = p;
  last_time = t;
  clicked_button = last_button = b;
  if (alt_state > ALT_NONE)
    alt_state = ALT_CANCELLED;
}

void
win_mouse_release(mouse_button b, LPARAM lp)
{
  win_show_mouse();
  if (b == clicked_button) {
    term_mouse_release(b, get_mods(), get_mouse_pos(lp));
    clicked_button = 0;
    ReleaseCapture();
  }
}  
Beispiel #3
0
int cryptofs_write(CtxLocal *ctx, char *_file, long long offset, unsigned long count, char *buf)
{
    long long block;
    unsigned long mempos = 0;
    unsigned long blocksize = crypto_get_blocksize(ctx);
    int fp;
    gchar *file;
    gboolean error = FALSE;

    file = crypto_translate_path(ctx, _file);
    if ((fp = open(file, O_RDWR)) < 0){
	g_free(file);
	return -1;
    }
    g_free(file);

    block = offset / blocksize;

    for (block = offset / blocksize; block * blocksize < offset + count; block++) {
	unsigned long inblock_offset = 0;
	unsigned long inblock_count = 0;

	translate_pos(offset, count, block, blocksize, &inblock_offset, &inblock_count);

	if ((inblock_offset != 0) && (inblock_count != blocksize)) {
	    if (crypto_readblock(ctx, fp, block) < 0) {
		error = TRUE;
		break;
	    }
	}

	memmove(crypto_get_filebuf(ctx) + inblock_offset, buf + mempos, inblock_count);

	if (crypto_writeblock(ctx, fp, block, inblock_offset + inblock_count) < 0) {
	    error = TRUE;
	    break;
	}

	mempos += inblock_count;
    }

    close(fp);

    return error ? -1 : mempos;
}
Beispiel #4
0
static pos
translate_pos(int x, int y)
{
  return (pos){
    .x = floorf((x - PADDING) / (float)font_width ),
    .y = floorf((y - PADDING) / (float)font_height),
  };
}

static LPARAM last_lp = -1;
static pos last_pos = {-1, -1};

static pos
get_mouse_pos(LPARAM lp)
{
  last_lp = lp;
  return translate_pos(GET_X_LPARAM(lp), GET_Y_LPARAM(lp));
}
Beispiel #5
0
int cryptofs_read(CtxLocal *ctx, char *_file, long long offset, unsigned long count, char *buf)
{
    long long block;
    unsigned long mempos = 0;
    unsigned long blocksize = crypto_get_blocksize(ctx);
    int fp;
    gchar *file;
    gboolean error = FALSE;

    file = crypto_translate_path(ctx, _file);
    if ((fp = open(file, 0)) < 0){
	g_free(file);
	return -1;
    }
    g_free(file);

    block = offset / blocksize;

    for (block = offset / blocksize; block * blocksize < offset + count; block++) {
	unsigned long inblock_offset = 0;
	unsigned long inblock_count = 0;
	unsigned long inblock_read = 0;
	long res = 0;

	translate_pos(offset, count, block, blocksize, &inblock_offset, &inblock_count);

	if ((res = crypto_readblock(ctx, fp, block)) < 0) {
	    error = TRUE;
	    break;
	}
	inblock_read = res - inblock_offset;

	memmove(buf + mempos, crypto_get_filebuf(ctx) + inblock_offset, inblock_read);

	mempos += inblock_read;
	if (inblock_read < inblock_count)
	    break;
    }
    close(fp);

    return error ? -1 : mempos;
}
Beispiel #6
0
  pos p = get_mouse_pos(lp);
  if (nc || (p.x == last_pos.x && p.y == last_pos.y))
    return;

  last_pos = p;
  term_mouse_move(get_mods(), p);
}

void
win_mouse_wheel(WPARAM wp, LPARAM lp)
{
  // WM_MOUSEWHEEL reports screen coordinates rather than client coordinates
  POINT wpos = {.x = GET_X_LPARAM(lp), .y = GET_Y_LPARAM(lp)};
  ScreenToClient(wnd, &wpos);
  pos tpos = translate_pos(wpos.x, wpos.y);

  int delta = GET_WHEEL_DELTA_WPARAM(wp);  // positive means up
  int lines_per_notch;
  SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &lines_per_notch, 0);

  term_mouse_wheel(delta, lines_per_notch, get_mods(), tpos);
}


/* Keyboard handling */

static void
send_syscommand(WPARAM cmd)
{
  SendMessage(wnd, WM_SYSCOMMAND, cmd, ' ');