Exemple #1
0
zoom_start()
/* Starts the first part of zooming--moving the red cross to the upper right
   corner of the area to zoom.  This gets called by menu choice "zoom in". */
{
	int x, y;

	if ( ! zoom_ok () )
	{
		return;
	}
	zoom_push ();

	x1 = xorg; x2 = xend;
	y1 = yorg; y2 = yend;

	x = dev_x;
	y = dev_y;

	x -= 10; y += 10;

	if ( x >= xorg && x <= xend )
		x1 = x;

	if ( y >= yorg && y <= yend )
		y1 = y;

	set_mark();
	mask_red ();

	mask_line ( x1 - 5, y1, x1 + 5, y1 );
	mask_line ( x1, y1 + 5, x1, y1 - 5 );
	XFlush ( x_display );

	last_x1 = x1; last_y1 = y1;

	zooming = 1;
	set_zoom_menus( True );
}
Exemple #2
0
static void e_line_from_point(
	struct PPM *ppm,
	char *mask,
	struct E2D *E,
	int s_row,
	int s_col,
	COLOR color
	)
{
	int row, col;
	int w = ppm->w;
	int h = ppm->h;
	float radius = 8;
	char flag_clean = 0;

	row = s_row;
	col = s_col;
	while (1) {
		int d_row, d_col;
		int d_gcd;
		int index;
		char flag_break = 0;

		if (row < 0 || row >= h || col < 0 || col >= w) {
			break;
		}

		index = row * w + col;

		if (mask[index] == MASK_E_LINIE
			|| mask[index] == MASK_E_LINIE_TMP) {
			flag_clean = 1;
			break;
		}
		/* else */
		if (mask[index]) {
			break;
		}

		if (E[index].mod == 0) {
			mask[index] = MASK_E_LINIE_TMP;
			break;
		}

		d_row = rint(E[index].y / E[index].mod * radius);
		d_col = rint(E[index].x / E[index].mod * radius);

		d_gcd = gcd(abs(d_row), abs(d_col));

		if (d_gcd > 1) {
			d_row /= d_gcd;
			d_col /= d_gcd;
		}

		row += d_row;
		col += d_col;

		index = row * w + col;

		if (row < 0 || row >= h || col < 0 || col >= w || mask[index]) {
			flag_break = 1;
		}

		if (d_row == 0 && d_col == 0) {
			break;
		}

		if (!mask_line(h, w, mask, row - d_row, col - d_col, row , col)) {
			/* if uncomment, the E lines can not be overlaped,
			   but its dense will not be clear */
#ifdef STRICT_NO_OVERLAP
			flag_clean = 1;
#endif
			break;
		}

		if (flag_break || row < 0 || row >= h || col < 0 || col >= w) {
			break;
		} else {
			/* unmasking the end point could cause loops */
			mask[index] = MASK_NONE;
		}
	 }

	/* reset start point !!! */
	mask[s_row * w + s_col] = MASK_NONE;

	/* backword */
	row = s_row;
	col = s_col;
	while (1) {
		int d_row, d_col;
		int d_gcd;
		int index;
		char flag_break = 0;

		if (row < 0 || row >= h || col < 0 || col >= w) {
			break;
		}

		index = row * w + col;

		if (mask[index] == MASK_E_LINIE
			|| mask[index] == MASK_E_LINIE_TMP) {
			flag_clean = 1;
			break;
		}
		/* else */
		if (mask[index]) {
			break;
		}

		if (E[index].mod == 0) {
			mask[index] = MASK_E_LINIE_TMP;
			break;
		}

		d_row = -rint(E[index].y / E[index].mod * radius);
		d_col = -rint(E[index].x / E[index].mod * radius);

		d_gcd = gcd(abs(d_row), abs(d_col));

		if (d_gcd > 1) {
			d_row /= d_gcd;
			d_col /= d_gcd;
		}

		row += d_row;
		col += d_col;

		index = row * w + col;

		if (row < 0 || row >= h || col < 0 || col >= w || mask[index]) {
			flag_break = 1;
		}

		if (d_row == 0 && d_col == 0) {
			break;
		}

		if (!mask_line(h, w, mask, row - d_row, col - d_col, row , col)) {
			/* if uncomment, the E lines can not be overlaped,
			   but its dense will not be clear */
#ifdef STRICT_NO_OVERLAP
			flag_clean = 1;
#endif
			break;
		}

		if (flag_break || row < 0 || row >= h || col < 0 || col >= w) {
			break;
		} else {
			/* unmasking the end point could cause loops */
			mask[index] = MASK_NONE;
		}
	}

	if (flag_clean) {
		/* the start point must be masked,
		 * or it will be twice visited */
		int index = s_row * w + s_col;
		if (mask[index] == MASK_NONE
			|| mask[index] == MASK_E_LINIE_TMP)
		{
			mask[index] = MASK_E_LINIE;
		}
	}

	/* mark the space around the drawed points  */
	for (row = 0; row < h; ++row) {
		for (col = 0; col < w; ++col) {
			int index = row * w + col;

			if (mask[index] != MASK_E_LINIE_TMP) {
				continue;
			}

			if (flag_clean) {
				mask[index] = MASK_NONE;
				continue;
			}

			mask[index] = MASK_E_LINIE;
			PPM_setpixel(row, col, ppm, color);

			if (row > 0) {
				if (mask[index - w] == MASK_NONE) {
					mask[index - w] = MASK_E_LINIE;
				}
				if (col > 0) {
					if (mask[index - w - 1] == MASK_NONE) {
						mask[index - w - 1] = MASK_E_LINIE;
					}
				}
				if (col < w - 1) {
					if (mask[index - w + 1] == MASK_NONE) {
						mask[index - w + 1] = MASK_E_LINIE;
					}
				}
			}

			if (row < h - 1) {
				if (mask[index + w] == MASK_NONE) {
					mask[index + w] = MASK_E_LINIE;
				}
				if (col > 0) {
					if (mask[index + w - 1] == MASK_NONE) {
						mask[index + w - 1] = MASK_E_LINIE;
					}
				}
				if (col < w - 1) {
					if (mask[index + w + 1] == MASK_NONE) {
						mask[index + w + 1] = MASK_E_LINIE;
					}
				}
			}

			if (col > 0) {
				if (mask[index - 1] == MASK_NONE) {
					mask[index - 1] = MASK_E_LINIE;
				}
			}

			if (col < w - 1) {
				if (mask[index + 1] == MASK_NONE) {
					mask[index + 1] = MASK_E_LINIE;
				}
			}
		}
	}
}