Example #1
0
/*
 * Display tiles.
 */
static void display_tiles(int col, int row, int height, int width,
						  byte attr_top, byte char_left)
{
	int i, j;

	/* Clear the display lines */
	for (i = 0; i < height; i++)
		Term_erase(col, row + i, width);

	width = logical_width(width);
	height = logical_height(height);

	/* Display lines until done */
	for (i = 0; i < height; i++) {
		/* Display columns until done */
		for (j = 0; j < width; j++) {
			byte a;
			unsigned char c;
			int x = col + actual_width(j);
			int y = row + actual_height(i);
			int ia, ic;

			ia = attr_top + i;
			ic = char_left + j;

			a = (byte) ia;
			c = (unsigned char) ic;

			/* Display symbol */
			big_pad(x, y, a, c);
		}
	}
}
Example #2
0
/*
 *  Do tile picker command -- Change tiles
 */
static bool tile_picker_command(ui_event ke, bool * tile_picker_ptr,
								int height, int width, byte * attr_top_ptr,
								byte * char_left_ptr, byte * cur_attr_ptr,
								byte * cur_char_ptr, int col, int row,
								int *delay)
{
	static byte attr_old = 0;
	static char char_old = 0;

	/* These are the distance we want to maintain between the cursor and
	 * borders. */
	int frame_left = logical_width(10);
	int frame_right = logical_width(10);
	int frame_top = logical_height(4);
	int frame_bottom = logical_height(4);

	/* Get mouse movement */
	if (ke.type == EVT_MOUSE) {
		int eff_width = actual_width(width);
		int eff_height = actual_height(height);
		byte a = *cur_attr_ptr;
		byte c = *cur_char_ptr;

		int my = logical_height(ke.mouse.y - row);
		int mx = logical_width(ke.mouse.x - col);

		if ((my >= 0) && (my < eff_height) && (mx >= 0) && (mx < eff_width)
			&& ((ke.mouse.button == 1) || (a != *attr_top_ptr + my)
				|| (c != *char_left_ptr + mx))) {
			/* Set the visual */
			*cur_attr_ptr = a = *attr_top_ptr + my;
			*cur_char_ptr = c = *char_left_ptr + mx;

			/* Move the frame */
			if (*char_left_ptr > MAX(0, (int) c - frame_left))
				(*char_left_ptr)--;
			if (*char_left_ptr + eff_width <=
				MIN(255, (int) c + frame_right))
				(*char_left_ptr)++;
			if (*attr_top_ptr > MAX(0, (int) a - frame_top))
				(*attr_top_ptr)--;
			if (*attr_top_ptr + eff_height <=
				MIN(255, (int) a + frame_bottom))
				(*attr_top_ptr)++;

			/* Delay */
			*delay = 100;

			/* Accept change */
			if (ke.mouse.button)
				remove_tiles(col, row, tile_picker_ptr, width, height);

			return TRUE;
		}

		/* Cancel change */
		else if (ke.mouse.button == 2) {
			*cur_attr_ptr = attr_old;
			*cur_char_ptr = char_old;
			remove_tiles(col, row, tile_picker_ptr, width, height);

			return TRUE;
		}

		else {
			return FALSE;
		}
	}

	if (ke.type != EVT_KBRD)
		return FALSE;


	switch (ke.key.code) {
	case ESCAPE:
		{
			if (*tile_picker_ptr) {
				/* Cancel change */
				*cur_attr_ptr = attr_old;
				*cur_char_ptr = char_old;
				remove_tiles(col, row, tile_picker_ptr, width, height);

				return TRUE;
			}

			break;
		}

	case KC_ENTER:
		{
			if (*tile_picker_ptr) {
				/* Accept change */
				remove_tiles(col, row, tile_picker_ptr, width, height);
				return TRUE;
			}

			break;
		}

	case 'V':
	case 'v':
		{
			/* No visual mode without graphics, for now - NRM */
			if (current_graphics_mode != NULL)
				if (current_graphics_mode->grafID == 0)
					break;

			if (!*tile_picker_ptr) {
				*tile_picker_ptr = TRUE;
				bigcurs = TRUE;

				*attr_top_ptr =
					(byte) MAX(0, (int) *cur_attr_ptr - frame_top);
				*char_left_ptr =
					(char) MAX(0, (int) *cur_char_ptr - frame_left);

				attr_old = *cur_attr_ptr;
				char_old = *cur_char_ptr;
			} else {
				/* Cancel change */
				*cur_attr_ptr = attr_old;
				*cur_char_ptr = char_old;
				remove_tiles(col, row, tile_picker_ptr, width, height);
			}

			return TRUE;
		}

	case 'C':
	case 'c':
		{
			/* Set the tile */
			attr_idx = *cur_attr_ptr;
			char_idx = *cur_char_ptr;

			return TRUE;
		}

	case 'P':
	case 'p':
		{
			if (attr_idx) {
				/* Set the char */
				*cur_attr_ptr = attr_idx;
				*attr_top_ptr =
					(byte) MAX(0, (int) *cur_attr_ptr - frame_top);
			}

			if (char_idx) {
				/* Set the char */
				*cur_char_ptr = char_idx;
				*char_left_ptr =
					(char) MAX(0, (int) *cur_char_ptr - frame_left);
			}

			return TRUE;
		}

	default:
		{
			int d = target_dir(ke.key);
			byte a = *cur_attr_ptr;
			byte c = *cur_char_ptr;

			if (!*tile_picker_ptr)
				break;

			bigcurs = TRUE;

			/* Restrict direction */
			if ((a == 0) && (ddy[d] < 0))
				d = 0;
			if ((c == 0) && (ddx[d] < 0))
				d = 0;
			if ((a == 255) && (ddy[d] > 0))
				d = 0;
			if ((c == 255) && (ddx[d] > 0))
				d = 0;

			a += ddy[d];
			c += ddx[d];

			/* Set the tile */
			*cur_attr_ptr = a;
			*cur_char_ptr = c;

			/* Move the frame */
			if (ddx[d] < 0 &&
				*char_left_ptr > MAX(0, (int) c - frame_left))
				(*char_left_ptr)--;
			if ((ddx[d] > 0) &&
				*char_left_ptr + (width / tile_width) <=
				MIN(255, (int) c + frame_right))
				(*char_left_ptr)++;

			if (ddy[d] < 0 && *attr_top_ptr > MAX(0, (int) a - frame_top))
				(*attr_top_ptr)--;
			if (ddy[d] > 0 &&
				*attr_top_ptr + (height / tile_height) <=
				MIN(255, (int) a + frame_bottom))
				(*attr_top_ptr)++;

			/* We need to always eat the input even if it is clipped,
			 * otherwise it will be interpreted as a change object
			 * selection command with messy results.
			 */
			return TRUE;
		}
	}


	/* Tile picker command is not used */
	return FALSE;
}
Example #3
0
/*
 *  Do glyph picker command -- Change glyphs
 */
static bool glyph_command(ui_event ke, bool * glyph_picker_ptr,
						  int height, int width, byte * cur_attr_ptr,
						  wchar_t * cur_char_ptr, int col, int row)
{
	static byte attr_old = 0;
	static char char_old = 0;

	/* Get mouse movement */
	if (ke.type == EVT_MOUSE) {
		byte a = *cur_attr_ptr;

		int mx = logical_width(ke.mouse.x - col);

		if (ke.mouse.y != row + height / 2)
			return FALSE;

		if ((mx >= 0) && (mx < MAX_COLORS) && (ke.mouse.button == 1)) {
			/* Set the visual */
			*cur_attr_ptr = a = mx - 14;

			/* Accept change */
			remove_tiles(col, row, glyph_picker_ptr, width, height);

			return TRUE;
		}

		else {
			return FALSE;
		}
	}

	if (ke.type != EVT_KBRD)
		return FALSE;


	switch (ke.key.code) {
	case ESCAPE:
		{
			if (*glyph_picker_ptr) {
				/* Cancel change */
				*cur_attr_ptr = attr_old;
				*cur_char_ptr = char_old;
				remove_tiles(col, row, glyph_picker_ptr, width, height);

				return TRUE;
			}

			break;
		}

	case KC_ENTER:
		{
			if (*glyph_picker_ptr) {
				/* Accept change */
				remove_tiles(col, row, glyph_picker_ptr, width, height);
				return TRUE;
			}

			break;
		}

	case 'V':
	case 'v':
		{
			if (!*glyph_picker_ptr) {
				*glyph_picker_ptr = TRUE;

				attr_old = *cur_attr_ptr;
				char_old = *cur_char_ptr;
			} else {
				/* Cancel change */
				*cur_attr_ptr = attr_old;
				*cur_char_ptr = char_old;
				remove_tiles(col, row, glyph_picker_ptr, width, height);
			}

			return TRUE;
		}

	case 'i':
	case 'I':
		{
			if (*glyph_picker_ptr) {
				char code_point[6];
				bool res = FALSE;

				/* Ask the user for a code point */
				Term_gotoxy(col, row + height / 2 + 2);
				res = get_string("(up to 5 hex digits):", code_point, 5);

				/* Process input */
				if (res) {
					unsigned long int point =
						strtoul(code_point, (char **) NULL, 16);
					*cur_char_ptr = (wchar_t) point;
					return TRUE;
				}
			}

			break;


		}

	default:
		{
			int d = target_dir(ke.key);
			byte a = *cur_attr_ptr;

			if (!*glyph_picker_ptr)
				break;

			/* Horizontal only */
			if (ddy[d] != 0)
				break;

			/* Horizontal movement */
			if (ddx[d] != 0) {
				a += ddx[d] + BASIC_COLORS;
				a = a % BASIC_COLORS;
				*cur_attr_ptr = a;
			}


			/* We need to always eat the input even if it is clipped,
			 * otherwise it will be interpreted as a change object
			 * selection command with messy results.
			 */
			return TRUE;
		}
	}


	/* Glyph picker command is not used */
	return FALSE;
}
Example #4
0
/*
 *  Do visual mode command -- Change symbols
 */
static bool visual_mode_command(ui_event_data ke, bool * visual_list_ptr,
				int height, int width, byte * attr_top_ptr,
				byte * char_left_ptr, byte * cur_attr_ptr,
				byte * cur_char_ptr, int col, int row,
				int *delay)
{
    static byte attr_old = 0;
    static char char_old = 0;

    /* These are the distance we want to maintain between the cursor and
     * borders. */
    int frame_left = logical_width(10);
    int frame_right = logical_width(10);
    int frame_top = logical_height(4);
    int frame_bottom = logical_height(4);

    switch (ke.key) {
    case ESCAPE:
	{
	    if (*visual_list_ptr) {
		/* Cancel change */
		*cur_attr_ptr = attr_old;
		*cur_char_ptr = char_old;
		remove_visual_list(col, row, visual_list_ptr, width, height);

		return TRUE;
	    }

	    break;
	}

    case '\n':
    case '\r':
	{
	    if (*visual_list_ptr) {
		/* Accept change */
		remove_visual_list(col, row, visual_list_ptr, width, height);
		return TRUE;
	    }

	    break;
	}

    case 'V':
    case 'v':
	{
	    if (!*visual_list_ptr) {
		*visual_list_ptr = TRUE;
		bigcurs = TRUE;

		*attr_top_ptr = (byte) MAX(0, (int) *cur_attr_ptr - frame_top);
		*char_left_ptr =
		    (char) MAX(0, (int) *cur_char_ptr - frame_left);

		attr_old = *cur_attr_ptr;
		char_old = *cur_char_ptr;
	    } else {
		/* Cancel change */
		*cur_attr_ptr = attr_old;
		*cur_char_ptr = char_old;
		remove_visual_list(col, row, visual_list_ptr, width, height);
	    }

	    return TRUE;
	}

    case 'C':
    case 'c':
	{
	    /* Set the visual */
	    attr_idx = *cur_attr_ptr;
	    char_idx = *cur_char_ptr;

	    return TRUE;
	}

    case 'P':
    case 'p':
	{
	    if (attr_idx) {
		/* Set the char */
		*cur_attr_ptr = attr_idx;
		*attr_top_ptr = (byte) MAX(0, (int) *cur_attr_ptr - frame_top);
	    }

	    if (char_idx) {
		/* Set the char */
		*cur_char_ptr = char_idx;
		*char_left_ptr =
		    (char) MAX(0, (int) *cur_char_ptr - frame_left);
	    }

	    return TRUE;
	}

    default:
	{
	    if (*visual_list_ptr) {
		int eff_width = actual_width(width);
		int eff_height = actual_height(height);
		int d = target_dir(ke.key);
		byte a = *cur_attr_ptr;
		byte c = *cur_char_ptr;

		bigcurs = TRUE;

		/* Get mouse movement */
		if (ke.type == EVT_MOUSE) {
		    int my = ke.mousey - row;
		    int mx = ke.mousex - col;

		    my = logical_height(my);
		    mx = logical_width(mx);

		    if ((my >= 0) && (my < eff_height) && (mx >= 0)
			&& (mx < eff_width)
			&& ((ke.index) || (a != *attr_top_ptr + my)
			    || (c != *char_left_ptr + mx))) {
			/* Set the visual */
			*cur_attr_ptr = a = *attr_top_ptr + my;
			*cur_char_ptr = c = *char_left_ptr + mx;

			/* Move the frame */
			if (*char_left_ptr > MAX(0, (int) c - frame_left))
			    (*char_left_ptr)--;
			if (*char_left_ptr + eff_width <=
			    MIN(255, (int) c + frame_right))
			    (*char_left_ptr)++;
			if (*attr_top_ptr > MAX(0, (int) a - frame_top))
			    (*attr_top_ptr)--;
			if (*attr_top_ptr + eff_height <=
			    MIN(255, (int) a + frame_bottom))
			    (*attr_top_ptr)++;

			/* Delay */
			*delay = 100;

			/* Accept change */
			if (ke.index)
			    remove_visual_list(col, row, visual_list_ptr, width,
					       height);

			return TRUE;
		    }

		    /* Cancel change */
		    else if (ke.index) {
			*cur_attr_ptr = attr_old;
			*cur_char_ptr = char_old;
			remove_visual_list(col, row, visual_list_ptr, width,
					   height);

			return TRUE;
		    }
		} else {
		    /* Restrict direction */
		    if ((a == 0) && (ddy[d] < 0))
			d = 0;
		    if ((c == 0) && (ddx[d] < 0))
			d = 0;
		    if ((a == 255) && (ddy[d] > 0))
			d = 0;
		    if ((c == 255) && (ddx[d] > 0))
			d = 0;

		    a += ddy[d];
		    c += ddx[d];

		    /* Set the visual */
		    *cur_attr_ptr = a;
		    *cur_char_ptr = c;

		    /* Move the frame */
		    if ((ddx[d] < 0)
			&& *char_left_ptr > MAX(0, (int) c - frame_left))
			(*char_left_ptr)--;
		    if ((ddx[d] > 0)
			&& *char_left_ptr + eff_width <= MIN(255,
							     (int) c +
							     frame_right))
			(*char_left_ptr)++;

		    if ((ddy[d] < 0)
			&& *attr_top_ptr > MAX(0, (int) a - frame_top))
			(*attr_top_ptr)--;
		    if ((ddy[d] > 0)
			&& *attr_top_ptr + eff_height <= MIN(255,
							     (int) a +
							     frame_bottom))
			(*attr_top_ptr)++;

		    /* We need to always eat the input even if it is clipped,
		     * otherwise it will be interpreted as a change object
		     * selection command with messy results. */
		    return TRUE;
		}
	    }
	}
    }

    /* Visual mode command is not used */
    return FALSE;
}