Ejemplo n.º 1
0
//
// Button - Initializes a button.
//
void EZ_button_Init(ez_button_t *button, 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)
{
	// Initialize the inherited class first.
	EZ_control_Init(&button->super, tree, parent, name, description, x, y, width, height, flags);

	// Initilize the button specific stuff.
	((ez_control_t *)button)->CLASS_ID	= EZ_BUTTON_ID;

	// TODO : Make a default macro for button flags.
	((ez_control_t *)button)->ext_flags	|= (flags | control_focusable | control_contained | control_bg_tile_center | control_bg_tile_edges);

	// Override the draw function.
	CONTROL_REGISTER_EVENT(button, EZ_button_OnDraw, OnDraw, ez_control_t);
	CONTROL_REGISTER_EVENT(button, EZ_button_OnResize, OnResize, ez_control_t);
	CONTROL_REGISTER_EVENT(button, EZ_button_OnMouseClick, OnMouseClick, ez_control_t);
	CONTROL_REGISTER_EVENT(button, EZ_button_OnMouseLeave, OnMouseLeave, ez_control_t);
	CONTROL_REGISTER_EVENT(button, EZ_button_OnMouseEnter, OnMouseEnter, ez_control_t);	
	CONTROL_REGISTER_EVENT(button, EZ_button_OnMouseDown, OnMouseDown, ez_control_t);
	CONTROL_REGISTER_EVENT(button, EZ_button_OnMouseUp, OnMouseUp, ez_control_t);	

	// Button specific events.
	CONTROL_REGISTER_EVENT(button, EZ_button_OnAction, OnAction, ez_button_t);
	CONTROL_REGISTER_EVENT(button, EZ_button_OnTextAlignmentChanged, OnTextAlignmentChanged, ez_button_t);
	CONTROL_REGISTER_EVENT(button, EZ_button_OnToggled, OnToggled, ez_button_t);

	// Create the buttons text label.
	{
		button->text_label = EZ_label_Create(tree, (ez_control_t *)button, "Button text label", "", button->padding_left, button->padding_top, 1, 1, 0, 0, "");

		EZ_label_AddOnTextChanged(button->text_label, EZ_button_OnLabelTextChanged, NULL);

		// Don't allow any interaction with the label, it's just there to show text.
		EZ_label_SetReadOnly(button->text_label, true);
		EZ_label_SetTextSelectable(button->text_label, false);
		EZ_label_SetAutoSize(button->text_label, true);
		EZ_control_SetIgnoreMouse((ez_control_t *)button->text_label, true);
		EZ_control_SetFocusable((ez_control_t *)button->text_label, false);
		EZ_control_SetMovable((ez_control_t *)button->text_label, false);

		CONTROL_RAISE_EVENT(NULL, ((ez_control_t *)button), ez_control_t, OnResize, NULL);
	}

	EZ_button_SetNormalImage(button, EZ_BUTTON_DEFAULT_NORMAL_IMAGE);
	EZ_button_SetHoverImage(button, EZ_BUTTON_DEFAULT_HOVER_IMAGE);
	EZ_button_SetPressedImage(button, EZ_BUTTON_DEFAULT_PRESSED_IMAGE);
	EZ_button_SetToggledHoverImage(button, EZ_BUTTON_DEFAULT_PRESSED_HOVER_IMAGE);

	button->ext_flags |= button_use_images;

	EZ_button_SetColorOrBackground((ez_control_t *)button, button->normal_image, button->color_normal);
}
Ejemplo n.º 2
0
//
// Listview item - Adds a column to the listview item.
//
void EZ_listviewitem_AddColumn(ez_listviewitem_t *self, ez_listview_subitem_t data, int width)
{
    int column = 0;
    ez_label_t *label = NULL;
    ez_control_t *ctrl = (ez_control_t *)self;

    if (self->item_count >= sizeof(self->items))
    {
        Sys_Error("EZ_listviewitem_AddColumn: Max allowed columns %i exceeded.\n", sizeof(self->items));
    }

    // Create a new label to use as the column.
    label = EZ_label_Create(ctrl->control_tree, ctrl, "Listview item column", "", 0, 0, width, 5, 0, 0, data.text);
    EZ_control_SetPayload(ctrl, data.payload);
    EZ_control_SetAnchor(ctrl, anchor_left | anchor_top | anchor_bottom);

    // Add the item to the columns.
    self->items[self->item_count] = label;
    column = self->item_count;
    self->item_count++;

    CONTROL_RAISE_EVENT(NULL, ctrl, ez_listviewitem_t, OnColumnAdded, (void *)column);
}