Exemple #1
0
void ftr_wait_for_mouse_click3(struct FTR *f, int *x, int *y, int *b)
{
	ftr_set_handler(f, "button", handle_click_wait3);
	int r = ftr_loop_run(f);
	int bit = r % 2;
	r /= 2;
	if (x) *x = r % 10000;
	if (y) *y = r / 10000;
	if (b) *b = bit ? FTR_BUTTON_LEFT : FTR_BUTTON_RIGHT;
}
Exemple #2
0
void pan_key_handler(struct FTR *f, int k, int m, int x, int y)
{
	//fprintf(stderr, "PAN_KEY_HANDLER  %d '%c' (%d) at %d %d\n",
	//		k, isalnum(k)?k:' ', m, x, y);

	//if (k == '+') action_increase_zoom(f, f->w/2, f->h/2);
	//if (k == '-') action_decrease_zoom(f, f->w/2, f->h/2);
	if (k == '+') action_change_zoom_by_factor(f, f->w/2, f->h/2, 2);
	if (k == '-') action_change_zoom_by_factor(f, f->w/2, f->h/2, 0.5);
	if (k == 'p') action_change_zoom_by_factor(f, f->w/2, f->h/2, 1.1);
	if (k == 'm') action_change_zoom_by_factor(f, f->w/2, f->h/2, 1/1.1);
	if (k == 'P') action_change_zoom_by_factor(f, f->w/2, f->h/2, 1.006);
	if (k == 'M') action_change_zoom_by_factor(f, f->w/2, f->h/2, 1/1.006);
	if (k == ' ') action_cycle(f, 1);
	if (k == '\b') action_cycle(f, -1);

	if (isdigit(k)) action_select_image(f, (k-'0')?(k-'0'-1):10);
	//if (k == 'a') action_contrast_change(f, 1.3, 0);
	//if (k == 'A') action_contrast_change(f, 1/1.3, 0);
	//if (k == 'b') action_contrast_change(f, 1, 1);
	//if (k == 'B') action_contrast_change(f, 1, -1);
	if (k == 'n') action_qauto(f);

	// if ESC or q, exit
	if  (k == '\033' || k == 'q')
		ftr_notify_the_desire_to_stop_this_loop(f, 1);

	// arrows move the viewport
	if (k > 1000) {
		int d[2] = {0, 0};
		int inc = -10;
		if (m & FTR_MASK_SHIFT  ) inc /= 10;
		if (m & FTR_MASK_CONTROL) inc *= 10;
		switch (k) {
		case FTR_KEY_LEFT : d[0] -= inc; break;
		case FTR_KEY_RIGHT: d[0] += inc; break;
		case FTR_KEY_UP   : d[1] -= inc; break;
		case FTR_KEY_DOWN : d[1] += inc; break;
		}
		if (k == FTR_KEY_PAGE_UP)   d[1] = +f->h/3;
		if (k == FTR_KEY_PAGE_DOWN) d[1] = -f->h/3;
		action_offset_viewport(f, d[0], d[1]);
	}

	// if 'k', do weird things
	if (k == 'k') {
		fprintf(stderr, "setting key_handler_print\n");
		ftr_set_handler(f, "key", key_handler_print);
	}
}
Exemple #3
0
int main()
{
	struct terminal t[1];
	t->w = 80;
	t->h = 25;
	t->kerning = 0;
	t->spacing = 0;
	t->font[0] = reformat_font(*xfont9x15, UNPACKED);
	t->letters = malloc(sizeof(int) * t->w * t->h);
	t->attributes = malloc(sizeof(int) * t->w * t->h);
	t->cursorx = t->cursory = 0;
	int w = (t->w + t->kerning) * t->font->width;
	int h = (t->h + t->spacing) * t->font->height;

	term_puts(t, "");

	struct FTR f = ftr_new_window(w, h);
	f.userdata = t;
	f.changed = 1;

	ftr_set_handler(&f, "expose", term_exposer);
	ftr_set_handler(&f, "key", term_key_handler);
	return ftr_loop_run(&f);
}
Exemple #4
0
int main_pan(int c, char *v[])
{
	// process input arguments
	char *imask_option = pick_option(&c, &v, "m", "");
	if (c > 4) {
		fprintf(stderr, "usage:\n\t"
				"%s [in.fft [out.fft [out.mask]]]\n", *v);
		//                0  1       2        3
		return c;
	}
	char *filename_in   = c > 1 ? v[1] : "-";
	char *filename_out  = c > 2 ? v[2] : "-";
	char *filename_mask = c > 3 ? v[3] : NULL;
	char *filename_imask = *imask_option ? imask_option : NULL;


	// read image
	struct pan_state e[1];
	int pd;
	e->fft = (void*)iio_read_image_float_vec(filename_in, &e->w, &e->h,&pd);
	if (pd != 2 && pd != 6)
		return fprintf(stderr, "input must be a fft (got pd=%d)\n", pd);
	e->pd = pd / 2;
	create_pyramid(e);
	if (filename_imask) {
		int mw, mh;
		e->mask = iio_read_image_uint8(filename_imask,&mw,&mh);
		if (mw != e->w || mh != e->h)
			return fprintf(stderr, "input mask bad size\n");
		fprintf(stderr, "using input mask from file \"%s\"\n",
				filename_imask);
	} else {
		e->mask = malloc(e->w * e->h);
		memset(e->mask, 1, e->w * e->h);
	}

	// open window
	struct FTR f = ftr_new_window(BAD_MIN(e->w,512), BAD_MIN(e->h,512));
	f.userdata = e;
	action_reset_zoom_and_position(&f);
	ftr_set_handler(&f, "expose", pan_exposer);
	ftr_set_handler(&f, "motion", pan_motion_handler);
	ftr_set_handler(&f, "button", pan_button_handler);
	ftr_set_handler(&f, "key"   , pan_key_handler);
	int r = ftr_loop_run(&f);

	// apply computed mask
	for (int i = 0; i < e->w * e->h; i++)
		if (!e->mask[i])
			for (int l = 0; l < e->pd; l++)
				e->fft[i*e->pd+l] = 0;

	// save output images
	iio_save_image_float_vec(filename_out, (void*)e->fft, e->w,e->h, pd);
	if (filename_mask)
		iio_save_image_uint8_vec(filename_mask, e->mask, e->w, e->h, 1);

	// cleanup and exit (optional)
	ftr_close(&f);
	return r;
}