// // Scrollbar - Initializes a scrollbar. // void EZ_scrollbar_Init(ez_scrollbar_t *scrollbar, 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(&scrollbar->super, tree, parent, name, description, x, y, width, height, flags); // Initilize the button specific stuff. ((ez_control_t *)scrollbar)->CLASS_ID = EZ_SCROLLBAR_ID; ((ez_control_t *)scrollbar)->ext_flags |= (flags | control_focusable | control_contained | control_resizeable); // Override control events. CONTROL_REGISTER_EVENT(scrollbar, EZ_scrollbar_Destroy, OnDestroy, ez_control_t); CONTROL_REGISTER_EVENT(scrollbar, EZ_scrollbar_OnResize, OnResize, ez_control_t); CONTROL_REGISTER_EVENT(scrollbar, EZ_scrollbar_OnParentResize, OnParentResize, ez_control_t); CONTROL_REGISTER_EVENT(scrollbar, EZ_scrollbar_OnMouseEvent, OnMouseEvent, ez_control_t); CONTROL_REGISTER_EVENT(scrollbar, EZ_scrollbar_OnMouseDown, OnMouseDown, ez_control_t); CONTROL_REGISTER_EVENT(scrollbar, EZ_scrollbar_OnMouseUpOutside, OnMouseUpOutside, ez_control_t); CONTROL_REGISTER_EVENT(scrollbar, EZ_scrollbar_OnParentScroll, OnParentScroll, ez_control_t); // Scrollbar specific events. CONTROL_REGISTER_EVENT(scrollbar, EZ_scrollbar_OnTargetChanged, OnTargetChanged, ez_scrollbar_t); scrollbar->back = EZ_button_Create(tree, (ez_control_t *)scrollbar, "Scrollbar back button", "", 0, 0, 0, 0, control_contained | control_enabled); scrollbar->forward = EZ_button_Create(tree, (ez_control_t *)scrollbar, "Scrollbar forward button", "", 0, 0, 0, 0, control_contained | control_enabled); scrollbar->slider = EZ_button_Create(tree, (ez_control_t *)scrollbar, "Scrollbar slider button", "", 0, 0, 0, 0, control_contained | control_enabled); EZ_control_AddOnMouseDown((ez_control_t *)scrollbar->slider, EZ_scrollbar_OnSliderMouseDown, NULL); EZ_control_AddOnMouseDown((ez_control_t *)scrollbar->back, EZ_scrollbar_OnBackButtonMouseDown, NULL); EZ_control_AddOnMouseDown((ez_control_t *)scrollbar->forward, EZ_scrollbar_OnForwardButtonMouseDown, NULL); scrollbar->slider_minsize = 5; scrollbar->scroll_delta_x = 1; scrollbar->scroll_delta_y = 1; // Listen to repeated mouse events so that we continue scrolling when // holding down the mouse button over the scroll arrows. EZ_control_SetListenToRepeatedMouseClicks((ez_control_t *)scrollbar->back, true); EZ_control_SetListenToRepeatedMouseClicks((ez_control_t *)scrollbar->forward, true); // TODO : Remove this test stuff. /* { EZ_button_SetNormalColor(scrollbar->back, 255, 125, 125, 125); EZ_button_SetNormalColor(scrollbar->forward, 255, 125, 125, 125); EZ_button_SetNormalColor(scrollbar->slider, 255, 125, 125, 125); } */ CONTROL_RAISE_EVENT(NULL, (ez_control_t *)scrollbar, ez_control_t, OnResize, NULL); }
// // Window - Initializes a window. // void EZ_window_Init(ez_window_t *window, 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) { ez_control_t *window_ctrl = (ez_control_t *)window; ez_control_t *titlebar_ctrl = NULL; ez_control_t *scrollpane_ctrl = NULL; int rh_size = 0; // Initialize the inherited class first. EZ_control_Init(&window->super, tree, parent, name, description, x, y, width, height, flags); ((ez_control_t *)window)->CLASS_ID = EZ_WINDOW_ID; ((ez_control_t *)window)->ext_flags |= (flags | control_focusable | control_contained | control_resizeable); rh_size = window_ctrl->resize_handle_thickness; // Set the background. EZ_control_SetBackgroundImage(window_ctrl, EZ_WINDOW_DEFAULT_BACKGROUND_IMAGE); EZ_control_SetBackgroundImageOpacity(window_ctrl, 1.0); EZ_control_SetBackgroundImageEdgePercentage(window_ctrl, 20); // Title bar. { // Set the tilebar to move it's parent. window->titlebar = EZ_control_Create(tree, window_ctrl, "Window titlebar", NULL, rh_size, rh_size, window_ctrl->width, 15, (control_focusable | control_move_parent | control_movable | control_resizeable | control_enabled | control_anchor_viewport)); titlebar_ctrl = (ez_control_t *)window->titlebar; EZ_control_SetBackgroundImage(titlebar_ctrl, "gfx/ui/ez_titlebar"); // Set the size to fit within the resize handles. EZ_control_SetSize(titlebar_ctrl, (window_ctrl->width - (2 * rh_size)), 15); EZ_control_SetAnchor(titlebar_ctrl, (anchor_left | anchor_top | anchor_right)); EZ_control_SetDrawOrder(titlebar_ctrl, window_ctrl->draw_order + 1, true); // Close button. { #define CLOSE_BUTTON_EDGE_GAP 2 int cb_sidelength = 0; ez_control_t *close_ctrl = NULL; window->close_button = EZ_button_Create(tree, titlebar_ctrl, "Close button", NULL, 0, 0, 10, 10, control_enabled); close_ctrl = (ez_control_t *)window->close_button; cb_sidelength = (titlebar_ctrl->height - (2 * CLOSE_BUTTON_EDGE_GAP)); // Position the close button CLOSE_BUTTON_EDGE_GAP number of pixels from the edge // of the titlebar, and size it accordingly. EZ_control_SetPosition(close_ctrl, -CLOSE_BUTTON_EDGE_GAP, CLOSE_BUTTON_EDGE_GAP); EZ_control_SetSize(close_ctrl, cb_sidelength, cb_sidelength); EZ_control_SetAnchor(close_ctrl, (anchor_top | anchor_right)); } } // Scrollpane. { window->scrollpane = EZ_scrollpane_Create(tree, window_ctrl, "Window scrollpane", NULL, rh_size, (rh_size + titlebar_ctrl->height), 10, 10, 0); scrollpane_ctrl = (ez_control_t *)window->scrollpane; // Size the scrollpane to fit inside the window control. EZ_control_SetSize(scrollpane_ctrl, (window_ctrl->width - (2 * rh_size)), (window_ctrl->height - (titlebar_ctrl->height + (2 * rh_size)))); EZ_control_SetAnchor(scrollpane_ctrl, (anchor_left | anchor_right | anchor_bottom | anchor_top)); // Window area. { window->window_area = EZ_control_Create(tree, scrollpane_ctrl, "Window area", NULL, 0, 0, 10, 10, (control_scrollable | control_enabled | control_resizeable)); // Set the window area as the target of the scrollpane // (this will make it a child of the scrollpane, so don't bother to add it as a child to the window itself). EZ_scrollpane_SetTarget(window->scrollpane, window->window_area); EZ_control_SetDrawOrder(window->window_area, scrollpane_ctrl->draw_order + 1, true); } } }