/** * @brief Activate the node. Can be used without the mouse (ie. a button will execute onClick) */ static void UI_RadioButtonNodeActivate (uiNode_t * node) { /* no cvar given? */ if (!EXTRADATA(node).cvar || !*(char*)(EXTRADATA(node).cvar)) { Com_Printf("UI_RadioButtonNodeClick: node '%s' doesn't have a valid cvar assigned\n", UI_GetPath(node)); return; } /* its not a cvar! */ /** @todo the parser should already check that the property value is a right cvar */ if (!Q_strstart((const char *)(EXTRADATA(node).cvar), "*cvar")) return; UI_GetReferenceFloat(node, EXTRADATA(node).cvar); /* Is we click on the already selected button, we can continue */ if (UI_RadioButtonNodeIsSelected(node)) return; { const char *cvarName = &((const char *)(EXTRADATA(node).cvar))[6]; if (EXTRADATA(node).string == NULL) { Cvar_SetValue(cvarName, EXTRADATA(node).value); } else { Cvar_Set(cvarName, EXTRADATA(node).string); } if (node->onChange) UI_ExecuteEventActions(node, node->onChange); } }
/** * @brief Activate the node. Can be used without the mouse (ie. a button will execute onClick) */ void uiRadioButtonNode::onActivate (uiNode_t* node) { /* no cvar given? */ if (!EXTRADATA(node).cvar || !*(char*)(EXTRADATA(node).cvar)) { Com_Printf("UI_RadioButtonNodeClick: node '%s' doesn't have a valid cvar assigned\n", UI_GetPath(node)); return; } /* its not a cvar! */ /** @todo the parser should already check that the property value is a right cvar */ char const* const cvarName = Q_strstart((char const*)(EXTRADATA(node).cvar), "*cvar:"); if (!cvarName) return; UI_GetReferenceFloat(node, EXTRADATA(node).cvar); /* Is we click on the already selected button, we can continue */ if (UI_RadioButtonNodeIsSelected(node)) return; if (EXTRADATA(node).string == nullptr) { Cvar_SetValue(cvarName, EXTRADATA(node).value); } else { Cvar_Set(cvarName, "%s", EXTRADATA(node).string); } if (node->onChange) { UI_ExecuteEventActions(node, node->onChange); } if (node->lua_onChange != LUA_NOREF) { UI_ExecuteLuaEventScript(node, node->lua_onChange); } }
/** * @brief Handles RadioButton draw * @todo need to implement image. We can't do everything with only one icon (or use another icon) */ static void UI_RadioButtonNodeDraw (uiNode_t *node) { vec2_t pos; uiSpriteStatus_t iconStatus; const qboolean disabled = node->disabled || node->parent->disabled; int texY; const char *image; const qboolean isSelected = UI_RadioButtonNodeIsSelected(node); if (disabled) { iconStatus = SPRITE_STATUS_DISABLED; texY = UI_4STATUS_TEX_HEIGHT * 2; } else if (isSelected) { iconStatus = SPRITE_STATUS_CLICKED; texY = UI_4STATUS_TEX_HEIGHT * 3; } else if (node->state) { iconStatus = SPRITE_STATUS_HOVER; texY = UI_4STATUS_TEX_HEIGHT; } else { iconStatus = SPRITE_STATUS_NORMAL; texY = 0; } UI_GetNodeAbsPos(node, pos); image = UI_GetReferenceString(node, node->image); if (image) { const int texX = 0; UI_DrawNormImageByName(qfalse, pos[0], pos[1], node->size[0], node->size[1], texX + node->size[0], texY + node->size[1], texX, texY, image); } if (EXTRADATA(node).background) { UI_DrawSpriteInBox(qfalse, EXTRADATA(node).background, iconStatus, pos[0], pos[1], node->size[0], node->size[1]); } if (EXTRADATA(node).icon) { UI_DrawSpriteInBox(EXTRADATA(node).flipIcon, EXTRADATA(node).icon, iconStatus, pos[0], pos[1], node->size[0], node->size[1]); } }