/** * @brief Create/remove close button on window. * @note Creates a onClick event handler, should be refactored. */ void UI_Window_SetCloseButton (uiNode_t* node, bool value) { if (value) { uiNode_t* control = UI_AllocNode(WINDOW_CLOSE_BUTTON_NAME, "button", node->dynamic); const int positionFromRight = CONTROLS_PADDING; static const char* closeCommand = "ui_close <path:root>;"; control->root = node; UI_NodeSetProperty(control, UI_GetPropertyFromBehaviour(control->behaviour, "icon"), "icons/system_close"); /** @todo Once @c image_t is known on the client, use @c image->width resp. @c image->height here */ control->box.size[0] = CONTROLS_IMAGE_DIMENSIONS; control->box.size[1] = CONTROLS_IMAGE_DIMENSIONS; control->box.pos[0] = node->box.size[0] - positionFromRight - control->box.size[0]; control->box.pos[1] = CONTROLS_PADDING; control->tooltip = _("Close the window"); control->onClick = UI_AllocStaticCommandAction(closeCommand); UI_AppendNode(node, control); } else { // drop the close node uiNode_t* control = UI_FindNode(node, WINDOW_CLOSE_BUTTON_NAME); if (control) { UI_RemoveNode (node, control); } } EXTRADATA(node).closeButton = value; }
/** * @brief Called at the end of the load from script */ void uiWindowNode::onLoaded (uiNode_t* node) { /* create a drag zone, if it is requested */ if (EXTRADATA(node).dragButton) { uiNode_t* control = UI_AllocNode("move_window_button", "controls", node->dynamic); control->root = node; control->box.size[0] = node->box.size[0]; control->box.size[1] = TOP_HEIGHT; control->box.pos[0] = 0; control->box.pos[1] = 0; control->tooltip = _("Drag to move window"); UI_AppendNode(node, control); } /* create a close button, if it is requested */ if (EXTRADATA(node).closeButton) { uiNode_t* button = UI_AllocNode("close_window_button", "button", node->dynamic); const int positionFromRight = CONTROLS_PADDING; static const char* closeCommand = "ui_close <path:root>;"; button->root = node; UI_NodeSetProperty(button, UI_GetPropertyFromBehaviour(button->behaviour, "icon"), "icons/system_close"); /** @todo Once @c image_t is known on the client, use @c image->width resp. @c image->height here */ button->box.size[0] = CONTROLS_IMAGE_DIMENSIONS; button->box.size[1] = CONTROLS_IMAGE_DIMENSIONS; button->box.pos[0] = node->box.size[0] - positionFromRight - button->box.size[0]; button->box.pos[1] = CONTROLS_PADDING; button->tooltip = _("Close the window"); button->onClick = UI_AllocStaticCommandAction(closeCommand); UI_AppendNode(node, button); } EXTRADATA(node).isFullScreen = node->box.size[0] == VID_NORM_WIDTH && node->box.size[1] == VID_NORM_HEIGHT; if (EXTRADATA(node).starLayout) UI_Invalidate(node); }