00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "../ui_main.h"
00038 #include "../ui_actions.h"
00039 #include "../ui_icon.h"
00040 #include "../ui_parse.h"
00041 #include "../ui_input.h"
00042 #include "../ui_render.h"
00043 #include "ui_node_radiobutton.h"
00044 #include "ui_node_abstractnode.h"
00045
00046 #define EXTRADATA_TYPE radioButtonExtraData_t
00047 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00048 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
00049
00050 #define EPSILON 0.001f
00051
00053 #define UI_4STATUS_TEX_HEIGHT 64
00054
00059 static void UI_RadioButtonNodeDraw (uiNode_t *node)
00060 {
00061 vec2_t pos;
00062 uiIconStatus_t iconStatus;
00063 const float current = UI_GetReferenceFloat(node, EXTRADATA(node).cvar);
00064 const qboolean disabled = node->disabled || node->parent->disabled;
00065 int texY;
00066 const char *image;
00067
00068 if (disabled) {
00069 iconStatus = ICON_STATUS_DISABLED;
00070 texY = UI_4STATUS_TEX_HEIGHT * 2;
00071 } else if (current > EXTRADATA(node).value - EPSILON && current < EXTRADATA(node).value + EPSILON) {
00072 iconStatus = ICON_STATUS_CLICKED;
00073 texY = UI_4STATUS_TEX_HEIGHT * 3;
00074 } else if (node->state) {
00075 iconStatus = ICON_STATUS_HOVER;
00076 texY = UI_4STATUS_TEX_HEIGHT;
00077 } else {
00078 iconStatus = ICON_STATUS_NORMAL;
00079 texY = 0;
00080 }
00081
00082 UI_GetNodeAbsPos(node, pos);
00083
00084 image = UI_GetReferenceString(node, node->image);
00085 if (image) {
00086 const int texX = 0;
00087 UI_DrawNormImageByName(pos[0], pos[1], node->size[0], node->size[1],
00088 texX + node->size[0], texY + node->size[1], texX, texY, image);
00089 }
00090
00091 if (EXTRADATA(node).icon) {
00092 UI_DrawIconInBox(EXTRADATA(node).icon, iconStatus, pos[0], pos[1], node->size[0], node->size[1]);
00093 }
00094 }
00095
00099 static void UI_RadioButtonNodeActivate (uiNode_t * node)
00100 {
00101 float current;
00102
00103
00104 if (!EXTRADATA(node).cvar || !*(char*)(EXTRADATA(node).cvar)) {
00105 Com_Printf("UI_RadioButtonNodeClick: node '%s' doesn't have a valid cvar assigned\n", UI_GetPath(node));
00106 return;
00107 }
00108
00109
00111 if (strncmp((const char *)(EXTRADATA(node).cvar), "*cvar", 5))
00112 return;
00113
00114 current = UI_GetReferenceFloat(node, EXTRADATA(node).cvar);
00115
00116 if (current > EXTRADATA(node).value - EPSILON && current < EXTRADATA(node).value + EPSILON)
00117 return;
00118
00119 {
00120 const char *cvarName = &((const char *)(EXTRADATA(node).cvar))[6];
00121 UI_SetCvar(cvarName, NULL, EXTRADATA(node).value);
00122 if (node->onChange)
00123 UI_ExecuteEventActions(node, node->onChange);
00124 }
00125 }
00126
00130 static void UI_RadioButtonNodeClick (uiNode_t * node, int x, int y)
00131 {
00132 if (node->onClick)
00133 UI_ExecuteEventActions(node, node->onClick);
00134
00135 UI_RadioButtonNodeActivate(node);
00136 }
00137
00138 static const value_t properties[] = {
00139
00140 {"value", V_FLOAT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, value), MEMBER_SIZEOF(EXTRADATA_TYPE, value)},
00141
00142 {"cvar", V_UI_CVAR, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, cvar), 0},
00143
00144 {"icon", V_UI_ICONREF, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, icon), MEMBER_SIZEOF(EXTRADATA_TYPE, icon)},
00145
00146 {NULL, V_NULL, 0, 0}
00147 };
00148
00149 void UI_RegisterRadioButtonNode (uiBehaviour_t *behaviour)
00150 {
00151 behaviour->name = "radiobutton";
00152 behaviour->draw = UI_RadioButtonNodeDraw;
00153 behaviour->leftClick = UI_RadioButtonNodeClick;
00154 behaviour->activate = UI_RadioButtonNodeActivate;
00155 behaviour->properties = properties;
00156 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00157 }