Esempio n. 1
0
// key_in: If not -1, this means to use this key as input, and not call game_poll()
int UI_WINDOW::process(int key_in,int process_mouse)
{
	UI_GADGET *tmp;

	// only does stuff in non THREADED mode
	os_poll();

	if (process_mouse){
		ui_mouse_process();
	}

	if (key_in == -1){
		keypress = game_check_key();
	} else {
		keypress = key_in;
	}

	last_keypress = keypress;
	do_dump_check();
	if (mouse_captured_gadget && B1_RELEASED){
		mouse_captured_gadget = NULL;
	}

	// The following code was commented out by NeilK on 4/15/99 to fix a problem we were having with
	//	the UI_SLIDER2 class not receiving the process event when the mouse was dragging the scroller
	// but outside the mask region. I checked a handful of other screens and so no adverse affects
	// of this change at the time.

/*
	if (mouse_captured_gadget) {
		mouse_captured_gadget->process();  // if a control has captured the mouse, only it gets processed
		use_hack_to_get_around_stupid_problem_flag = 0;
		return last_keypress;
	}
*/
	if (!first_gadget) {
		use_hack_to_get_around_stupid_problem_flag = 0;
		return last_keypress;
	}

	check_focus_switch_keys();

	// run through all top level gadgets and process them (they are responsible for processing
	// their children, which UI_GADGET will handle if you don't override process() or if you
	// do, you call UI_GADGET::process()).
	if ( !ignore_gadgets ) {
		tmp = first_gadget;
		do	{
			if ( !tmp->check_move() )
				tmp->process();

			tmp = tmp->next;

		} while (tmp != first_gadget);
	}

	use_hack_to_get_around_stupid_problem_flag = 0;
	return last_keypress;
}
Esempio n. 2
0
int snazzy_menu_do(ubyte *data, int mask_w, int mask_h, int num_regions, MENU_REGION *regions, int *action, int poll_key, int *key)
{
	int i, k, x, y, offset;
	int choice = -1, mouse_on_choice = -1;
	ubyte pixel_value = 0;

	Assert(data != NULL);
	Assert(num_regions > 0);
	Assert(regions != NULL);
	
	gr_reset_clip();  // don't remove
	mouse_get_pos_unscaled( &x, &y ); 

	// boundary conditions
	if((y > mask_h - 1) || (x > mask_w - 1)){
		pixel_value = 0;
	} else {
		// check the pixel value under the mouse
		offset = y * mask_w + x;
		pixel_value = *(data + (offset));
	}

	*action = -1;

	k = 0;
	if ( poll_key ) {
		k = game_check_key();
		if (key)
			*key = k;  // pass keypress back to caller
	}

//	if (mouse_down_count(MOUSE_LEFT_BUTTON) )	{
	if ( !mouse_down(MOUSE_LEFT_BUTTON) && Snazzy_mouse_left_was_down ) {
		//nprintf(("Alan", "pixel val: %d\n", pixel_value));
		for (i=0; i < num_regions; i++) {
			if (pixel_value == regions[i].mask) {
				choice = regions[i].mask;
				if ( regions[i].click_sound != -1 ) {
					snd_play( &Snds_iface[regions[i].click_sound], 0.0f );
				}
			}
		}	// end for
	}

	switch ( k ) {
		case KEY_ESC:
			choice = ESC_PRESSED;
			break;

		default:
			if ( k )
				for (i=0; i<num_regions; i++) {
					if ( !regions[i].key )
						continue;
					if (ascii_table[k] == regions[i].key || shifted_ascii_table[k] == regions[i].key) {
						choice = regions[i].mask;
						if ( regions[i].click_sound != -1 ) {
							snd_play( &Snds_iface[regions[i].click_sound], 0.0f );
						}
					}
			}	// end for

			break;

	} // end switch

	for (i=0; i<num_regions; i++) {
		if (pixel_value == regions[i].mask) {
			mouse_on_choice = regions[i].mask;	
			break;
		}
	}	// end for

	gr_set_color_fast(&Color_white);
	gr_set_font( FONT1 );

	if ((mouse_on_choice >= 0) && (mouse_on_choice <= (num_regions)) && (i >=0)) {
		gr_printf( 0x8000, 450, regions[i].text );
	}

	if ( mouse_down(MOUSE_LEFT_BUTTON) ){
		Snazzy_mouse_left_was_down = 1;
	} else {
		Snazzy_mouse_left_was_down = 0;
	}
	
	if ( choice > -1 || choice == ESC_PRESSED ) {
		*action = SNAZZY_CLICKED;
		return choice;
	}

	if ( mouse_on_choice > -1 ) {
		*action = SNAZZY_OVER;
		return mouse_on_choice;
	}

	return -1;
}