ui_node_checkbox.c
Go to the documentation of this file.00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "../ui_nodes.h"
00035 #include "../ui_parse.h"
00036 #include "../ui_main.h"
00037 #include "../ui_actions.h"
00038 #include "../ui_render.h"
00039 #include "ui_node_checkbox.h"
00040 #include "ui_node_abstractnode.h"
00041 #include "ui_node_abstractvalue.h"
00042
00043 #define EXTRADATA(node) UI_EXTRADATA(node, abstractValueExtraData_t)
00044
00045 static void UI_CheckBoxNodeDraw (uiNode_t* node)
00046 {
00047 const float value = UI_GetReferenceFloat(node, EXTRADATA(node).value);
00048 vec2_t pos;
00049 const char *image = UI_GetReferenceString(node, node->image);
00050 int texx, texy;
00051
00052
00053 if (!image || image[0] == '\0')
00054 return;
00055
00056
00057 if (node->disabled) {
00058 texy = 96;
00059 } else if (node->state) {
00060 texy = 32;
00061 } else {
00062 texy = 0;
00063 }
00064
00065
00066 if (value == 0) {
00067 texx = 0;
00068 } else if (value > 0) {
00069 texx = 32;
00070 } else {
00071 texx = 64;
00072 }
00073
00074 UI_GetNodeAbsPos(node, pos);
00075 UI_DrawNormImageByName(pos[0], pos[1], node->size[0], node->size[1],
00076 texx + node->size[0], texy + node->size[1], texx, texy, image);
00077 }
00078
00082 static void UI_CheckBoxNodeActivate (uiNode_t *node)
00083 {
00084 const float last = UI_GetReferenceFloat(node, EXTRADATA(node).value);
00085 float value;
00086
00087 if (node->disabled)
00088 return;
00089
00090
00091 value = (last > 0) ? 0 : 1;
00092 if (last == value)
00093 return;
00094
00095
00096 EXTRADATA(node).lastdiff = value - last;
00097 if (!strncmp(EXTRADATA(node).value, "*cvar:", 6)) {
00098 UI_SetCvar(&((char*)EXTRADATA(node).value)[6], NULL, value);
00099 } else {
00100 *(float*) EXTRADATA(node).value = value;
00101 }
00102
00103
00104 if (node->onChange) {
00105 UI_ExecuteEventActions(node, node->onChange);
00106 }
00107 }
00108
00109 static void UI_CheckBoxNodeCallActivate (uiNode_t *node, const uiCallContext_t *context)
00110 {
00111 UI_CheckBoxNodeActivate(node);
00112 }
00113
00117 static void UI_CheckBoxNodeClick (uiNode_t * node, int x, int y)
00118 {
00119 if (node->onClick)
00120 UI_ExecuteEventActions(node, node->onClick);
00121
00122 UI_CheckBoxNodeActivate(node);
00123 }
00124
00128 static void UI_CheckBoxNodeLoading (uiNode_t *node)
00129 {
00130 }
00131
00132 static const value_t properties[] = {
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 {"toggle", V_UI_NODEMETHOD, ((size_t) UI_CheckBoxNodeCallActivate), 0},
00143 {NULL, V_NULL, 0, 0}
00144 };
00145
00146 void UI_RegisterCheckBoxNode (uiBehaviour_t *behaviour)
00147 {
00148 behaviour->name = "checkbox";
00149 behaviour->extends = "abstractvalue";
00150 behaviour->draw = UI_CheckBoxNodeDraw;
00151 behaviour->leftClick = UI_CheckBoxNodeClick;
00152 behaviour->loading = UI_CheckBoxNodeLoading;
00153 behaviour->activate = UI_CheckBoxNodeActivate;
00154 behaviour->properties = properties;
00155 }