Ejemplo n.º 1
0
void ui_menu::handle_events()
{
	int stop = FALSE;
	ui_event local_menu_event;

	// loop while we have interesting events
	while (!stop && ui_input_pop_event(machine(), &local_menu_event))
	{
		switch (local_menu_event.event_type)
		{
			// if we are hovering over a valid item, select it with a single click
			case UI_EVENT_MOUSE_DOWN:
				if (hover >= 0 && hover < numitems)
					selected = hover;
				else if (hover == -2)
				{
					selected -= visitems - 1;
					validate_selection(1);
				}
				else if (hover == -1)
				{
					selected += visitems - 1;
					validate_selection(1);
				}
				break;

			// if we are hovering over a valid item, fake a UI_SELECT with a double-click
			case UI_EVENT_MOUSE_DOUBLE_CLICK:
				if (hover >= 0 && hover < numitems)
				{
					selected = hover;
					if (local_menu_event.event_type == UI_EVENT_MOUSE_DOUBLE_CLICK)
					{
						menu_event.iptkey = IPT_UI_SELECT;
						if (selected == numitems - 1)
						{
							menu_event.iptkey = IPT_UI_CANCEL;
							ui_menu::stack_pop(machine());
						}
					}
					stop = TRUE;
				}
				break;

			// translate CHAR events into specials
			case UI_EVENT_CHAR:
				menu_event.iptkey = IPT_SPECIAL;
				menu_event.unichar = local_menu_event.ch;
				stop = TRUE;
				break;

			// ignore everything else
			default:
				break;
		}
	}
}
Ejemplo n.º 2
0
const ui_menu_event *ui_menu::process(UINT32 flags)
{
	// reset the menu_event
	menu_event.iptkey = IPT_INVALID;

	// first make sure our selection is valid
	validate_selection(1);

	// draw the menu
	if (numitems > 1 && (item[0].flags & MENU_FLAG_MULTILINE) != 0)
		draw_text_box();
	else
		draw(flags & UI_MENU_PROCESS_CUSTOM_ONLY);

	// process input
	if (!(flags & UI_MENU_PROCESS_NOKEYS))
	{
		// read events
		handle_events();

		// handle the keys if we don't already have an menu_event
		if (menu_event.iptkey == IPT_INVALID)
			handle_keys(flags);
	}

	// update the selected item in the menu_event
	if (menu_event.iptkey != IPT_INVALID && selected >= 0 && selected < numitems)
	{
		menu_event.itemref = item[selected].ref;
		return &menu_event;
	}
	return nullptr;
}
Ejemplo n.º 3
0
// States are written in a 2D array. The second index m is meant to refer to
// the index of the state in the set of states, whereas the first index is a
// running index for saving the same set of states several times, e.g., after
// each iteration
void Datafile::write_state(size_t n, size_t m, State const& state) {
	assert(datalayout == state.datalayout);
	const hsize_t coords[1][2] = {{n, m}};
	const hsize_t min_size[2] = {n+1, m+1};
	try {
		// extend dataset if needed, and write the state at the position specified by indices n and m
		ensure_states_data();
		states_data.extend(min_size);
		space_2d.setExtentSimple(2, min_size);
		space_2d.selectElements(H5S_SELECT_SET, 1, reinterpret_cast<const hsize_t*>(coords));
		validate_selection(space_2d);
		states_data.write(state.data_ptr(), *state_type, scalar_space, space_2d);
	}
	catch(H5::Exception& e) {
		e.printError();
		throw;
	}
}
Ejemplo n.º 4
0
void Datafile::write_deviation_history(std::vector<double> deviation_history, size_t index) {
	const hsize_t N = deviation_history.size();
	const hsize_t min_size[2] = {index+1, N};
	const hsize_t count[2] = {1, N};
	const hsize_t start[2] = {index, 0};
	try {
		ensure_deviation_history_data();
		deviation_history_data.extend(min_size);
		space_2d.setExtentSimple(2, min_size);
		space_2d.selectHyperslab(H5S_SELECT_SET, count, start);
		validate_selection(space_2d);
		space_1d.setExtentSimple(1, &N);
		space_1d.selectAll();
		deviation_history_data.write(&(deviation_history.front()), double_type,
				space_1d, space_2d);
	}
	catch (H5::Exception& e) {
		e.printError();
		throw;
	}
}
Ejemplo n.º 5
0
// Write a whole StateSet in one go. The optional argument sort_order can be
// given to write states in an order different from their order in the
// StateSet (for example, in order of increasing energy).
void Datafile::write_stateset(StateSet const& stateset, int step, std::list<size_t> const* sort_order) {
	hsize_t states_cur_size[2];
	hsize_t state_history_cur_size[1];
	try {
		ensure_states_data();
		ensure_state_history_data();
		// calculate current size of states_data
		states_data.getSpace().getSimpleExtentDims(states_cur_size);
		// new slot for states will be same as states_cur_size[0]
		const hsize_t new_slot = states_cur_size[0];
		state_history_pair pair;
		pair.step = step;
		pair.index = static_cast<int>(new_slot);
		// calculate current size of state_history_data and extend by one
		state_history_data.getSpace().getSimpleExtentDims(state_history_cur_size);
		hsize_t new_size = state_history_cur_size[0]+1;
		state_history_data.extend(&new_size);
		space_1d.setExtentSimple(1, &new_size);
		space_1d.selectElements(H5S_SELECT_SET, 1, state_history_cur_size);
		validate_selection(space_1d);
		// record what was the step when states were saved
		state_history_data.write(&pair, state_history_type, scalar_space, space_1d);
		// write states
		const size_t N = stateset.get_num_states();
		if (sort_order == NULL)
			for (size_t m=0; m<N; m++)
				write_state(new_slot, m, stateset[m]);
		else {
			std::list<size_t>::const_iterator it = sort_order->begin();
			for (size_t m=0; m<N; m++) {
				write_state(new_slot, m, stateset[*it]);
				it++;
			}
		}
	}
	catch(H5::Exception& e) {
		e.printError();
		throw;
	}
}
Ejemplo n.º 6
0
void Datafile::write_time_step_history(size_t index, double eps) {
	// pack values of index and eps into a struct in memory
	time_step_history_pair pair;
	pair.step = static_cast<int>(index);
	pair.time_step = eps;
	try {
		ensure_time_step_history_data();
		// calculate current size, extend if needed, and write data. You know the drill.
		H5::DataSpace tempspace = time_step_history_data.getSpace();
		tempspace.selectAll();
		hsize_t cur_size = tempspace.getSelectNpoints();
		hsize_t new_size = cur_size + 1;
		space_1d.setExtentSimple(1, &new_size);
		time_step_history_data.extend(&new_size);
		space_1d.selectElements(H5S_SELECT_SET, 1, &cur_size);
		validate_selection(space_1d);
		time_step_history_data.write(&pair, time_step_history_type, scalar_space, space_1d);
	}
	catch(H5::Exception& e) {
		e.printError();
		throw;
	}
}
Ejemplo n.º 7
0
void ui_menu::handle_keys(UINT32 flags)
{
	int ignorepause = ui_menu::stack_has_special_main_menu();
	int ignoreright;
	int ignoreleft;
	int code;

	// bail if no items
	if (numitems == 0)
		return;

	// if we hit select, return TRUE or pop the stack, depending on the item
	if (exclusive_input_pressed(IPT_UI_SELECT, 0))
	{
		if (selected == numitems - 1)
		{
			menu_event.iptkey = IPT_UI_CANCEL;
			ui_menu::stack_pop(machine());
		}
		return;
	}

	// hitting cancel also pops the stack
	if (exclusive_input_pressed(IPT_UI_CANCEL, 0))
	{
		ui_menu::stack_pop(machine());
		return;
	}

	// validate the current selection
	validate_selection(1);

	// swallow left/right keys if they are not appropriate
	ignoreleft = ((item[selected].flags & MENU_FLAG_LEFT_ARROW) == 0);
	ignoreright = ((item[selected].flags & MENU_FLAG_RIGHT_ARROW) == 0);

	// accept left/right keys as-is with repeat
	if (!ignoreleft && exclusive_input_pressed(IPT_UI_LEFT, (flags & UI_MENU_PROCESS_LR_REPEAT) ? 6 : 0))
		return;
	if (!ignoreright && exclusive_input_pressed(IPT_UI_RIGHT, (flags & UI_MENU_PROCESS_LR_REPEAT) ? 6 : 0))
		return;

	// up backs up by one item
	if (exclusive_input_pressed(IPT_UI_UP, 6))
	{
		selected = (selected + numitems - 1) % numitems;
		validate_selection(-1);
	}

	// down advances by one item
	if (exclusive_input_pressed(IPT_UI_DOWN, 6))
	{
		selected = (selected + 1) % numitems;
		validate_selection(1);
	}

	// page up backs up by visitems
	if (exclusive_input_pressed(IPT_UI_PAGE_UP, 6))
	{
		selected -= visitems - 1;
		validate_selection(1);
	}

	// page down advances by visitems
	if (exclusive_input_pressed(IPT_UI_PAGE_DOWN, 6))
	{
		selected += visitems - 1;
		validate_selection(-1);
	}

	// home goes to the start
	if (exclusive_input_pressed(IPT_UI_HOME, 0))
	{
		selected = 0;
		validate_selection(1);
	}

	// end goes to the last
	if (exclusive_input_pressed(IPT_UI_END, 0))
	{
		selected = numitems - 1;
		validate_selection(-1);
	}

	// pause enables/disables pause
	if (!ignorepause && exclusive_input_pressed(IPT_UI_PAUSE, 0))
	{
		if (machine().paused())
			machine().resume();
		else
			machine().pause();
	}

	// handle a toggle cheats request
	if (ui_input_pressed_repeat(machine(), IPT_UI_TOGGLE_CHEAT, 0))
		machine().cheat().set_enable(!machine().cheat().enabled());

	// see if any other UI keys are pressed
	if (menu_event.iptkey == IPT_INVALID)
		for (code = IPT_UI_FIRST + 1; code < IPT_UI_LAST; code++)
		{
			if (code == IPT_UI_CONFIGURE || (code == IPT_UI_LEFT && ignoreleft) || (code == IPT_UI_RIGHT && ignoreright) || (code == IPT_UI_PAUSE && ignorepause))
				continue;
			if (exclusive_input_pressed(code, 0))
				break;
		}
}
Ejemplo n.º 8
0
void ui_menu_sliders::handle()
{
	const ui_menu_event *menu_event;

	/* process the menu */
	menu_event = process(UI_MENU_PROCESS_LR_REPEAT | (m_hidden ? UI_MENU_PROCESS_CUSTOM_ONLY : 0));
	if (menu_event != nullptr)
	{
		/* handle keys if there is a valid item selected */
		if (menu_event->itemref != nullptr && menu_event->type == ui_menu_item_type::SLIDER)
		{
			const slider_state *slider = (const slider_state *)menu_event->itemref;
			INT32 curvalue = (*slider->update)(machine(), slider->arg, slider->id, nullptr, SLIDER_NOCHANGE);
			INT32 increment = 0;
			bool alt_pressed = machine().input().code_pressed(KEYCODE_LALT) || machine().input().code_pressed(KEYCODE_RALT);
			bool ctrl_pressed = machine().input().code_pressed(KEYCODE_LCONTROL) || machine().input().code_pressed(KEYCODE_RCONTROL);
			bool shift_pressed = machine().input().code_pressed(KEYCODE_LSHIFT) || machine().input().code_pressed(KEYCODE_RSHIFT);

			switch (menu_event->iptkey)
			{
				/* toggle visibility */
				case IPT_UI_ON_SCREEN_DISPLAY:
					if (m_menuless_mode)
						ui_menu::stack_pop(machine());
					else
						m_hidden = !m_hidden;
					break;

				/* decrease value */
				case IPT_UI_LEFT:
					if (alt_pressed && shift_pressed)
						increment = -1;
					if (alt_pressed)
						increment = -(curvalue - slider->minval);
					else if (shift_pressed)
						increment = (slider->incval > 10) ? -(slider->incval / 10) : -1;
					else if (ctrl_pressed)
						increment = -slider->incval * 10;
					else
						increment = -slider->incval;
					break;

				/* increase value */
				case IPT_UI_RIGHT:
					if (alt_pressed && shift_pressed)
						increment = 1;
					if (alt_pressed)
						increment = slider->maxval - curvalue;
					else if (shift_pressed)
						increment = (slider->incval > 10) ? (slider->incval / 10) : 1;
					else if (ctrl_pressed)
						increment = slider->incval * 10;
					else
						increment = slider->incval;
					break;

				/* restore default */
				case IPT_UI_SELECT:
					increment = slider->defval - curvalue;
					break;
			}

			/* handle any changes */
			if (increment != 0)
			{
				INT32 newvalue = curvalue + increment;

				/* clamp within bounds */
				if (newvalue < slider->minval)
					newvalue = slider->minval;
				if (newvalue > slider->maxval)
					newvalue = slider->maxval;

				/* update the slider and recompute the menu */
				(*slider->update)(machine(), slider->arg, slider->id, nullptr, newvalue);
				reset(UI_MENU_RESET_REMEMBER_REF);
			}
		}

		/* if we are selecting an invalid item and we are hidden, skip to the next one */
		else if (m_hidden)
		{
			/* if we got here via up or page up, select the previous item */
			if (menu_event->iptkey == IPT_UI_UP || menu_event->iptkey == IPT_UI_PAGE_UP)
			{
				selected = (selected + item.size() - 1) % item.size();
				validate_selection(-1);
			}

			/* otherwise select the next item */
			else if (menu_event->iptkey == IPT_UI_DOWN || menu_event->iptkey == IPT_UI_PAGE_DOWN)
			{
				selected = (selected + 1) % item.size();
				validate_selection(1);
			}
		}
	}
}