static void UI_TBarNodeDraw (uiNode_t *node) { /* dataImageOrModel is the texture name */ float shx; vec2_t nodepos; const char* ref = UI_GetReferenceString(node, node->image); float pointWidth; float width; if (Q_strnull(ref)) return; UI_GetNodeAbsPos(node, nodepos); pointWidth = TEXTURE_WIDTH / 100.0; /* relative to the texture */ { float ps; const float min = UI_GetReferenceFloat(node, EXTRADATA(node).super.min); const float max = UI_GetReferenceFloat(node, EXTRADATA(node).super.max); float value = UI_GetReferenceFloat(node, EXTRADATA(node).super.value); /* clamp the value */ if (value > max) value = max; if (value < min) value = min; ps = (value - min) / (max - min) * 100; shx = EXTRADATA(node).texl[0]; /* left gap to the texture */ shx += round(ps * pointWidth); /* add size from 0..TEXTURE_WIDTH */ } width = (shx * node->size[0]) / TEXTURE_WIDTH; UI_DrawNormImageByName(qfalse, nodepos[0], nodepos[1], width, node->size[1], shx, EXTRADATA(node).texh[1], EXTRADATA(node).texl[0], EXTRADATA(node).texl[1], ref); }
/** * @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 Activate the node. Can be used without the mouse (ie. a button will execute onClick) */ static void UI_CheckBoxNodeActivate (uiNode_t *node) { const float last = UI_GetReferenceFloat(node, EXTRADATA(node).value); float value; if (node->disabled) return; /* update value */ value = (last > 0) ? 0 : 1; if (last == value) return; /* save result */ EXTRADATA(node).lastdiff = value - last; if (Q_strstart((const char *)EXTRADATA(node).value, "*cvar:")) { Cvar_SetValue(&((const char*)EXTRADATA(node).value)[6], value); } else { *(float*) EXTRADATA(node).value = value; } /* fire change event */ if (node->onChange) { UI_ExecuteEventActions(node, node->onChange); } }
static void UI_CheckBoxNodeDraw (uiNode_t* node) { const float value = UI_GetReferenceFloat(node, EXTRADATA(node).value); vec2_t pos; const char *image = UI_GetReferenceString(node, node->image); int texx, texy; /* image set? */ if (Q_strnull(image)) return; /* outer status */ if (node->disabled) { texy = 96; } else if (node->state) { texy = 32; } else { texy = 0; } /* inner status */ if (value == 0) { texx = 0; } else if (value > 0) { texx = 32; } else { /* value < 0 */ texx = 64; } UI_GetNodeAbsPos(node, pos); UI_DrawNormImageByName(qfalse, pos[0], pos[1], node->size[0], node->size[1], texx + node->size[0], texy + node->size[1], texx, texy, image); }
/** * @brief Return a string from a node property * @param[in] node Requested node * @param[in] property Requested property * @return Return a string value of a property, else nullptr, if the type is not supported */ const char* UI_GetStringFromNodeProperty (const uiNode_t* node, const value_t* property) { const int baseType = property->type & V_UI_MASK; assert(node); assert(property); switch (baseType) { case V_NOT_UI: /* common type */ return Com_ValueToStr(node, property->type, property->ofs); case V_UI_CVAR: switch ((int)property->type) { case V_CVAR_OR_FLOAT: { const float f = UI_GetReferenceFloat(node, Com_GetValue<void*>(node, property)); const int i = f; if (f == i) return va("%i", i); else return va("%f", f); } case V_CVAR_OR_LONGSTRING: case V_CVAR_OR_STRING: case V_UI_CVAR: return UI_GetReferenceString(node, Com_GetValue<char*>(node, property)); } break; default: break; } Com_Printf("UI_GetStringFromNodeProperty: Unsupported string getter for property type 0x%X (%s@%s)\n", property->type, UI_GetPath(node), property->string); return nullptr; }
static qboolean UI_RadioButtonNodeIsSelected (uiNode_t *node) { if (EXTRADATA(node).string == NULL) { const float current = UI_GetReferenceFloat(node, EXTRADATA(node).cvar); return current > EXTRADATA(node).value - EPSILON && current < EXTRADATA(node).value + EPSILON; } else { const char *current = UI_GetReferenceString(node, EXTRADATA(node).cvar); return Q_streq(current, EXTRADATA(node).string); } }