Beispiel #1
0
//
// Window - Set window area virtual size (The part where you can put controls in the window).
//
void EZ_window_SetWindowAreaMinVirtualSize(ez_window_t *window, int min_virtual_width, int min_virtual_height)
{
	if (window->window_area)
	{
		EZ_control_SetMinVirtualSize(window->window_area, min_virtual_width, min_virtual_height);
	}
}
Beispiel #2
0
//
// Scrollpane - Initializes a Scrollpane.
//
void EZ_scrollpane_Init(ez_scrollpane_t *scrollpane, ez_tree_t *tree, ez_control_t *parent,
							  char *name, char *description,
							  int x, int y, int width, int height,
							  ez_control_flags_t flags)
{
	int rh_size_h = 0;
	int rh_size_v = 0;
	ez_control_t *scrollpane_ctrl = (ez_control_t *)scrollpane;

	// Initialize the inherited class first.
	EZ_control_Init(&scrollpane->super, tree, parent, name, description, x, y, width, height, flags);

	// Initilize the button specific stuff.
	((ez_control_t *)scrollpane)->CLASS_ID	= EZ_SCROLLPANE_ID;
	((ez_control_t *)scrollpane)->ext_flags	|= (flags | control_focusable | control_contained | control_resizeable);

	// Override control events.
	CONTROL_REGISTER_EVENT(scrollpane, EZ_scrollpane_OnResize, OnResize, ez_control_t);

	// Scrollpane specific events.
	CONTROL_REGISTER_EVENT(scrollpane, EZ_scrollpane_OnTargetChanged, OnTargetChanged, ez_scrollpane_t);
	CONTROL_REGISTER_EVENT(scrollpane, EZ_scrollpane_OnScrollbarThicknessChanged, OnScrollbarThicknessChanged, ez_scrollpane_t);

	scrollpane->scrollbar_thickness = 10;

	rh_size_h = (scrollpane_ctrl->ext_flags & control_resize_h) ? scrollpane_ctrl->resize_handle_thickness : 0;
	rh_size_v = (scrollpane_ctrl->ext_flags & control_resize_v) ? scrollpane_ctrl->resize_handle_thickness : 0;

	EZ_control_SetMinVirtualSize(scrollpane_ctrl, 1, 1);

	scrollpane->int_flags |= (show_h_scrollbar | show_v_scrollbar);

	// Create vertical scrollbar.
	{
		scrollpane->v_scrollbar = EZ_scrollbar_Create(tree, scrollpane_ctrl, "Vertical scrollbar", "", 0, 0, 10, 10, control_anchor_viewport);
		EZ_control_SetVisible((ez_control_t *)scrollpane->v_scrollbar, true);
		EZ_control_SetPosition((ez_control_t *)scrollpane->v_scrollbar, -rh_size_h, rh_size_v);
		EZ_control_SetAnchor((ez_control_t *)scrollpane->v_scrollbar, (anchor_top | anchor_bottom | anchor_right));

		EZ_scrollbar_SetTargetIsParent(scrollpane->v_scrollbar, false);
 
		EZ_control_AddChild(scrollpane_ctrl, (ez_control_t *)scrollpane->v_scrollbar);
	}

	// Create horizontal scrollbar.
	{
		scrollpane->h_scrollbar = EZ_scrollbar_Create(tree, (ez_control_t *)scrollpane, "Horizontal scrollbar", "", 0, 0, 10, 10, control_anchor_viewport);
	
		EZ_control_SetVisible((ez_control_t *)scrollpane->h_scrollbar, true);
		EZ_control_SetPosition((ez_control_t *)scrollpane->h_scrollbar, rh_size_h, -rh_size_v);
		EZ_control_SetAnchor((ez_control_t *)scrollpane->h_scrollbar, (anchor_left | anchor_bottom | anchor_right));

		EZ_scrollbar_SetTargetIsParent(scrollpane->h_scrollbar, false);
		EZ_scrollbar_SetIsVertical(scrollpane->h_scrollbar, false);

		EZ_control_AddChild(scrollpane_ctrl, (ez_control_t *)scrollpane->h_scrollbar);
	}

	EZ_scrollpane_ResizeScrollbars(scrollpane);
}
Beispiel #3
0
//
// Scrollbar - OnResize event.
//
int EZ_scrollbar_OnResize(ez_control_t *self, void *ext_event_info)
{
	ez_scrollbar_t *scrollbar = (ez_scrollbar_t *)self;

	// Let the super class do it's thing first.
	EZ_control_OnResize(self, NULL);

	// Make sure the buttons are in the correct place.
	EZ_scrollbar_RepositionScrollButtons(scrollbar);
	EZ_scrollbar_CalculateSliderSize(scrollbar, ((scrollbar->ext_flags & target_parent) ? self->parent : scrollbar->target));

	// Reset the min virtual size to 1x1 so that the 
	// scrollbar won't stop resizing when it's parent is resized.
	EZ_control_SetMinVirtualSize(self, 1, 1);

	CONTROL_EVENT_HANDLER_CALL(NULL, self, ez_control_t, OnResize, NULL);
	return 0;
}
Beispiel #4
0
//
// Label - Calculates where in the label text that the wordwraps will be done.
//
static void EZ_label_CalculateWordwraps(ez_label_t *label)
{
	int i					= 0;
	int current_index		= -1;
	int last_index			= -1;
//	int current_col			= 0;
	int scaled_char_size	= label->scaled_char_size;

	label->num_rows			= 1;
	label->num_cols			= 0;

	if (label->text && (label->ext_flags & label_wraptext))
	{	
		// Wordwrap the string to the virtual size of the control and save the
		// indexes where each row ends in an array.
		while ((i < LABEL_MAX_WRAPS) && Util_GetNextWordwrapString(label->text, NULL, (current_index + 1), &current_index, LABEL_LINE_SIZE, label->super.virtual_width, scaled_char_size))
		{
			label->wordwraps[i].index = current_index;
			label->wordwraps[i].col = current_index - last_index;
			label->wordwraps[i].row = label->num_rows - 1;
			i++;

			// Find the number of rows and columns.
			label->num_cols = max(label->num_cols, label->wordwraps[i].col);
			label->num_rows++;

			last_index = current_index;
		}
	}
	else if (label->text)
	{
		// Normal non-wrapped text, still save new line locations.
		current_index = 0; // TODO : Will this be ok? Otherwise it will be -1, which definantly is bad :p

		while ((i < LABEL_MAX_WRAPS) && label->text[current_index])
		{
			if (label->text[current_index] == '\n')
			{
				label->wordwraps[i].index = current_index;
				label->wordwraps[i].col = current_index - last_index;
				label->wordwraps[i].row = label->num_rows - 1;
				i++;

				// Find the number of rows and columns.
				label->num_cols = max(label->num_cols, label->wordwraps[i].col);
				label->num_rows++;
			}
			
			current_index++;
		}
	}

	// Save the row/col information for the last row also.
	if (label->text)
	{
		label->wordwraps[i].index	= -1;
		label->wordwraps[i].row		= label->num_rows - 1;
		label->wordwraps[i].col		= label->text_length - label->wordwraps[max(0, i - 1)].index;
		label->num_cols				= max(label->num_cols, label->wordwraps[i].col);
	}
	else
	{
		// No text.
		label->wordwraps[0].index	= -1;
		label->wordwraps[0].row		= -1;
		label->wordwraps[0].col		= -1;
		label->num_cols				= 0;
		label->num_rows				= 0;
	}

	// Change the virtual height of the control to fit the text when wrapping.
	if (label->ext_flags & label_wraptext)
	{
		EZ_control_SetMinVirtualSize((ez_control_t *)label, label->super.virtual_width_min, scaled_char_size * (label->num_rows + 1));
	}
	else
	{
		EZ_control_SetMinVirtualSize((ez_control_t *)label, scaled_char_size * (label->num_cols + 1), scaled_char_size * (label->num_rows + 1));
	}
}