Ejemplo n.º 1
0
// ---------------------------------------------------------------------------------------
// input:
//			do_repeat		=>		property of button, set to 1 to allow pressed events if mouse
//										pointer is held over button with left mouse button down,
//										otherwise 0 (useful for buttons that scroll items)
//			ignore_focus	=>		whether to allow Enter/Spacebar to affect pressed state when
//										control has focus
//
void UI_BUTTON::create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h, int do_repeat, int ignore_focus)
{
	text = NULL;

	if (_text) {
		if ( strlen(_text) > 0 ) {
			text = strdup(_text);
		}
	}

	// register gadget with UI window
	base_create( wnd, UI_KIND_BUTTON, _x, _y, _w, _h );

	// initialize variables
	m_flags = 0;
	next_repeat = 0;
	m_just_highlighted_function = NULL;		// assume there is no callback
	m_disabled_function = NULL;				// ditto
	if (do_repeat) {
		m_flags |= BF_REPEATS;
		next_repeat = 1;
	}

	m_press_linger = 1;
	first_callback = 1;

	hotkey_if_focus = KEY_SPACEBAR;

	if (ignore_focus){
		m_flags |= BF_IGNORE_FOCUS;
	}

	custom_cursor_bmap = -1;
	previous_cursor_bmap = -1;
};
Ejemplo n.º 2
0
void init_gene(base **gene)
{
  for(int i = 0; i < EQN_GENE_LENGTH; i++)
  {
    gene[i] = base_create();
  }
}
Ejemplo n.º 3
0
void UI_KEYTRAP::create(UI_WINDOW* wnd, int key, void (*_user_function)(void))
{
	base_create(wnd, UI_KIND_BUTTON, 0, 0, 0, 0);

	pressed_down = 0;
	set_hotkey(key);
	set_callback(_user_function);

	parent = this;		// Ugly.  This keeps KEYTRAPS from getting keyboard control.
}
Ejemplo n.º 4
0
// ---------------------------------------------------------------------------------------
// UI_ICON::create()
//
//
void UI_ICON::create(UI_WINDOW *wnd, char *_text, int _x, int _y, int _w, int _h)
{
	if (_text)	
		text = vm_strdup(_text);
	else
		text = NULL;

	base_create(wnd, UI_KIND_ICON, _x, _y, _w, _h);
	m_flags = 0;
}
Ejemplo n.º 5
0
void UI_INPUTBOX::create(UI_WINDOW *wnd, int _x, int _y, int _w, int _text_len, char *_text, int _flags, int pixel_lim, color *clr)
{
	int tw, th;

	Assert(_text_len >= 0);
	Assert((int) strlen(_text) <= _text_len);
	gr_set_font(wnd->f_id);
	gr_get_string_size( &tw, &th, "*" );

	// check to see if the user passed in a text color otherwise use the default green color
	if (clr){
		text_color = clr;
	} else {
		text_color = &CBRIGHT;
	}

	base_create( wnd, UI_KIND_INPUTBOX, _x, _y, _w, th+4 );
	text = (char *) vm_malloc( _text_len + 1);

	// input boxes no longer use background
	_flags |= UI_INPUTBOX_FLAG_NO_BACK;
	
	// if its in "password" mode, allocate a second string
	// and copy it
	if (_flags & UI_INPUTBOX_FLAG_PASSWD) {
		passwd_text = (char *) vm_malloc(_text_len + 1);
		memset(passwd_text, INPUTBOX_PASSWD_CHAR, strlen(_text));
		passwd_text[strlen(_text)] = 0;

	} else {
		passwd_text = NULL;
	}

	init_cursor();

	if ( _text_len > 0 ) {
		strncpy( text, _text, _text_len );
	}
	text[_text_len] = 0;
	position = strlen(_text);
	oldposition = position;
	length = _text_len;
	pressed_down = 0;
//	first_time = 1;
	changed_flag = 0;
	flags = _flags;
	pixel_limit = pixel_lim;
	locked = 0;
	valid_chars = NULL;
	invalid_chars = NULL;
}
Ejemplo n.º 6
0
/// DOT_SLIDER class down here
void UI_DOT_SLIDER_NEW::create(UI_WINDOW *wnd, int _x, int _y, int _num_pos, char *bm_slider, int slider_mask,
																					char *bm_left, int left_mask, int left_x, int left_y,
																					char *bm_right, int right_mask, int right_x, int right_y,
																					int _dot_width)
{
	// no end buttons yet
	has_end_buttons = 0;

	// if any of the left/right arrow information is specified, make sure its _all_ specified
	if((bm_left != NULL) || (left_mask != -1) || (bm_right != NULL) || (right_mask != -1)){
		Assert((bm_left != NULL) && (left_mask >= 0) && (bm_right != NULL) && (right_mask >= 0));
		if((bm_left == NULL) || (left_mask < 0) || (bm_right == NULL) || (right_mask < 0)){
			return;
		}

		// now we know we have end buttons
		has_end_buttons = 1;
	}

	// internal stuff
	num_pos = _num_pos;
	base_create(wnd, UI_KIND_DOT_SLIDER_NEW, _x, _y, 0, 20);
	pos = 0;		
	dot_width = _dot_width;	

	// set bitmaps for the slider itself	
	button.create( wnd, "", _x, _y, 0, 0, 0, 1 );
	button.set_parent(this);
	button.link_hotspot(slider_mask);
	button.set_bmaps(bm_slider, num_pos, 0);	
	button.hide();
		
	// maybe setup buttons for the arrows
	if ( has_end_buttons ) {
		// Second button is the up (increase) button		
		up_button.create( wnd, "", right_x, right_y, 0, 0, 1, 1 );
		up_button.set_parent(this);
		up_button.set_highlight_action(common_play_highlight_sound);
		up_button.link_hotspot(right_mask);
		up_button.set_bmaps(bm_right);		

		// Third button is the down (decrease) button		
		down_button.create( wnd, "", left_x, left_y, 0, 0, 1, 1 );
		down_button.set_parent(this);
		down_button.set_highlight_action(common_play_highlight_sound);
		down_button.link_hotspot(left_mask);
		down_button.set_bmaps(bm_left);		
	}
}
Ejemplo n.º 7
0
void UI_CHECKBOX::create(UI_WINDOW *wnd, const char *_text, int _x, int _y, int _state )
{
	int _w, _h;

//	gr_get_string_size( &_w, &_h, "X" );
	_w = 18;
	_h = 18;

	if ( _text )	
		text = vm_strdup( _text );
	else
		text = NULL;

	base_create( wnd, UI_KIND_CHECKBOX, _x, _y, _w, _h );

	position = 0;
	pressed_down = 0;
	flag = _state;
}
Ejemplo n.º 8
0
void UI_SCROLLBAR::create(UI_WINDOW *wnd, int _x, int _y, int _h, int _start, int _stop, int _position, int _window_size)
{
	char *up = "^";
	char *down = "v";
	int bw = 20;

	base_create( wnd, UI_KIND_SCROLLBAR, _x, _y + bw, bw, _h - bw * 2 );

	up_button.create( wnd, up, _x, _y, bw, bw, 1 );
	up_button.set_parent(this);
	up_button.set_hotkey_if_focus(KEY_UP);

	down_button.create( wnd, down, _x, _y + _h - bw, bw, bw, 1 );
	down_button.set_parent(this);
	down_button.set_hotkey_if_focus(KEY_DOWN);

	horz = 0;
	start = _start;
	stop = _stop;
	position = _position;
	window_size = _window_size;
	bar_length = h;
	bar_position =  0;

	Assert( stop >= 0 );

	if (stop != start)
		bar_size = (window_size * h) / (stop - start + window_size + 1);
	else
		bar_size = h;

	if (bar_size < 7)
		bar_size = 7;

	bar_position = position - start;
	bar_position *= h - bar_size;
	bar_position /= stop - start;

	dragging = 0;
	last_scrolled = 0;
	moved = 1;
}
Ejemplo n.º 9
0
void UI_RADIO::create(UI_WINDOW *wnd, const char *_text, int _x, int _y, int _state, int _group )
{
	int _w, _h;

//	gr_get_string_size( &_w, &_h, "X" );
	_w = 18;
	_h = 18;

	if (_text)	
		text = strdup(_text);
	else
		text = NULL;

	base_create( wnd, UI_KIND_RADIO, _x, _y, _w, _h );

	position = 0;
	pressed_down = 0;
	flag = _state;
	group = _group;
};
Ejemplo n.º 10
0
// captureCallback is called when an item is "selected" by mouse release. That is, the user has clicked, dragged and _released_. 
// the callback is called when the scrollbar has been released
void UI_SLIDER2::create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, int _numberItems, const char *_bitmapSliderControl, void (* _upCallback)(), void (*_downCallback)(),
				void (* _captureCallback)()) {

	int buttonHeight, buttonWidth;

	base_create( wnd, UI_KIND_SLIDER2, _x, _y, _w, _h );

	Assert(_upCallback != NULL);
	Assert(_downCallback != NULL);

	upCallback = _upCallback;
	downCallback = _downCallback;

	captureCallback = _captureCallback;	

	Assert(_bitmapSliderControl != NULL);

	last_scrolled = 0;

	// set bitmap
	set_bmaps(_bitmapSliderControl, 3, 0);
	
	// determine possible positions
	bm_get_info(bmap_ids[S2_NORMAL],&buttonWidth, &buttonHeight, NULL, NULL, NULL);
	slider_w = buttonWidth;
	slider_h = buttonHeight;
	Assert(buttonHeight > 5);
	slider_half_h = (int)(buttonHeight / 2);
	numberPositions = _h - buttonHeight;
	
	Assert(numberPositions >= 0);
	currentItem = 0;
	currentPosition = 0;

	numberItems = _numberItems;
	if (numberItems <= 0) {
		disabled_flag = 1;
	}

	slider_mode = S2M_DEFAULT;
}
Ejemplo n.º 11
0
void UI_LISTBOX::create(UI_WINDOW *wnd, int _x, int _y, int _w, int _h, int _numitems, char **_list, char *_check_list, int _max_items)
{
	int tw, th, nrows;
	int real_h;

	gr_set_font(wnd->f_id);
	gr_get_string_size(&tw, &th, "*");

	nrows = _h / th;
	real_h = nrows * th;

	base_create( wnd, UI_KIND_LISTBOX, _x, _y, _w, real_h );

   max_items = _max_items;	
   list = _list;
	num_items = _numitems;
	check_list = _check_list;	
	num_items_displayed = nrows;

	first_item = 0;
	current_item = -1;
	toggled_item = -1;
	last_scrolled = 0;
	textheight = th;
	dragging = 0;
	selected_item = -1;
	key_buffer_count = 0;
	last_typed = timer_get_milliseconds();

	if (_numitems > nrows) {
		scrollbar.create( wnd, _x+_w+3, _y, real_h, 0, _numitems-nrows, 0, nrows );
		scrollbar.set_parent(this);
		has_scrollbar = 1;

	} else {
		has_scrollbar = 0;
	}
};
Ejemplo n.º 12
0
/// DOT_SLIDER class down here
void UI_DOT_SLIDER::create(UI_WINDOW *wnd, int _x, int _y, char *bm, int id, int end_buttons, int _num_pos)
{
	char	filename[MAX_PATH_LEN];
	int	bx, by, bw, hotspot;

	has_end_buttons = end_buttons;

	if ( has_end_buttons ) {
		bx = _x + 24;
		by = _y + 1;
		bw = 190;
		hotspot = id + 1;
	} else {
		bx = _x;
		by = _y;
		bw = 80;
		hotspot = id;
	}

	num_pos = _num_pos;

	sprintf(filename, "%s%.2d", bm, hotspot);
	first_frame = bm_load_animation(filename, &total_frames);
	if (first_frame < 0) {
		Error(LOCATION, "Could not load %s.ani\n", filename);
		disable();
		hide();
		return;
	}

	base_create(wnd, UI_KIND_DOT_SLIDER, bx, by, bw, 20);
	pos = 0;

	// A DOT_SLIDER has up to 3 child buttons..

	by = _y;

	// First button is the region with the dots
	button.create( wnd, "", bx, by, bw, 20, 0, 1 );
	button.set_parent(this);
	button.link_hotspot(hotspot);
	button.hide();

	if ( has_end_buttons ) {
		// Second button is the up (increase) button
		sprintf(filename, "%s%.2d", bm, id + 2);
		up_button.create( wnd, "", _x + 216, _y, 22, 24, 1, 1 );
		up_button.set_parent(this);
		up_button.set_highlight_action(common_play_highlight_sound);
		up_button.set_bmaps(filename);
		up_button.link_hotspot(id + 2);

		// Third button is the down (decrease) button
		sprintf(filename, "%s%.2d", bm, id);
		down_button.create( wnd, "", _x, _y, 22, 24, 1, 1 );
		down_button.set_parent(this);
		down_button.set_highlight_action(common_play_highlight_sound);
		down_button.set_bmaps(filename);
		down_button.link_hotspot(id);
	}
}