Esempio n. 1
0
int button_add_start(int top, int left, keycode_t keypress)
{
	button_mouse* button = RNEW(button_mouse);
	if (!button) {
		return -1;
	}
	button->label = NULL;
	button->left = left;
	button->right = left+1;
	button->top = top;
	button->bottom = top;
	button->mods = 0;
	button->key = keypress;
	button->fn = NULL;

	button->next = button_stack;
	button_stack = button;
	button_num++;
	return 0;
}
Esempio n. 2
0
/*
 * Make a backup of the current buttons
 */
void button_backup_all(void)
{
	button_backup *newbackup;

	newbackup = RNEW(button_backup);
	if (!newbackup) {
		return;
	}
	if (button_num == 0) {
		newbackup->buttons = NULL;
		newbackup->num = 0;
		newbackup->length = 0;
	} else {
		newbackup->buttons = C_RNEW(button_num, button_mouse);
		if (!(newbackup->buttons)) {
			FREE(newbackup);
			return;
		}
		/* Straight memory copy */
		(void) C_COPY(newbackup->buttons, button_mse, button_num,
					  button_mouse);

		newbackup->num = button_num;
		newbackup->length = button_length;
	}

	/* push the backup onto the stack */
	newbackup->next = button_backups;
	button_backups = newbackup;


	/* Check we haven't already done this */
	/*if (button_backup[0].key) return; */

	/* Straight memory copy */
	/*(void)C_COPY(button_backup, button_mse, MAX_MOUSE_BUTTONS, button_mouse); */
}
Esempio n. 3
0
/*
 * Make a backup of the current buttons
 */
bool button_backup_all(bool kill_all)
{
	button_backup *newbackup;

	newbackup = RNEW(button_backup);
	if(!newbackup) {
		return FALSE;
	}
	/* copy the 2d buttons */
	if (kill_all) {
		newbackup->buttons = button_stack;
		newbackup->num = button_num;
		button_stack = NULL;
		button_num = 0;
	} else {
		/* copy the buttons to new memory */
		button_mouse *dest, *src, *end;
		newbackup->buttons = NULL;
		newbackup->num = 0;
		end = NULL;
		src = button_stack;
		while (src) {
			dest = RNEW(button_mouse);
			if (!dest) {
				FREE(newbackup);
				return FALSE;
			}

			(void)C_COPY(dest, src, 1, button_mouse);
			if (src->label) {
				dest->label = (char*)string_make(src->label);
			}
			if (!(newbackup->buttons)) {
				newbackup->buttons = dest;
			}
			if (end) {
				end->next = dest;
			}
			end = dest;
			newbackup->num++;
			dest->next = NULL;
			src = src->next;
		}
#if 0
		int i;
		button_mouse *button;
		newbackup->buttons = C_RNEW(button_num, button_mouse);
		if (!(newbackup->buttons)) {
			FREE(newbackup);
			return FALSE;
		}
		button = button_stack;
		for (i=0; i<button_num; i++) {
			if (button) {
				/* Straight memory copy */
				(void)C_COPY(&(newbackup->buttons[i]), button, 1, button_mouse);
				if (button->label) {
					newbackup->buttons[i].label = string_make(button->label);
				}
				button = button->next;
			}
			if (button) {
				newbackup->buttons[i].next = &(newbackup->buttons[i+1]);
			}
		}
		newbackup->num = button_num;
#endif
	}

	/* copy the 1d buttons */
	if (button_1d_num == 0) {
		newbackup->buttons_1d = NULL;
		newbackup->num_1d = 0;
		newbackup->length_1d = 0;
	} else {
		newbackup->buttons_1d = C_RNEW(button_1d_num, button_mouse_1d);
		if (!(newbackup->buttons_1d)) {
			/* free the 2d buttons TODO */
			if (newbackup->buttons && !kill_all) {
				int i;
				for (i=0; i<newbackup->num; i++) {
					if (newbackup->buttons[i].label) {
						string_free(newbackup->buttons[i].label);
					}
				}
				FREE(newbackup->buttons);
			}
			FREE(newbackup);
			return FALSE;
		}
		/* Straight memory copy */
		(void)C_COPY(newbackup->buttons_1d, button_1d_list, button_1d_num, button_mouse_1d);

		newbackup->num_1d = button_1d_num;
		newbackup->length_1d = button_1d_length;
	}

	/* push the backup onto the stack */
	newbackup->next = button_backups;
	button_backups = newbackup;

	if (kill_all && (button_num || button_1d_num)) {
		button_kill_all();
	}

	/* Redraw */
	p_ptr->redraw |= (PR_BUTTONS);

	return TRUE;
}
Esempio n. 4
0
menu_type *menu_new(skin_id skin_id, const menu_iter *iter)
{
	menu_type *m = RNEW(menu_type);
	menu_init(m, skin_id, iter);
	return m;
}