ui_node_tbar.c
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "../ui_nodes.h"
00026 #include "../ui_parse.h"
00027 #include "../ui_render.h"
00028 #include "ui_node_tbar.h"
00029 #include "ui_node_abstractvalue.h"
00030 #include "ui_node_abstractnode.h"
00031
00032 #define EXTRADATA_TYPE tbarExtraData_t
00033 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00034 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
00035
00036 #define TEXTURE_WIDTH 250.0
00037
00038 static void UI_TBarNodeDraw (uiNode_t *node)
00039 {
00040
00041 float shx;
00042 vec2_t nodepos;
00043 const char* ref = UI_GetReferenceString(node, node->image);
00044 float pointWidth;
00045 float width;
00046 if (!ref || ref[0] == '\0')
00047 return;
00048
00049 UI_GetNodeAbsPos(node, nodepos);
00050
00051 pointWidth = TEXTURE_WIDTH / 100.0;
00052
00053 {
00054 float ps;
00055 const float min = UI_GetReferenceFloat(node, EXTRADATA(node).super.min);
00056 const float max = UI_GetReferenceFloat(node, EXTRADATA(node).super.max);
00057 float value = UI_GetReferenceFloat(node, EXTRADATA(node).super.value);
00058
00059 if (value > max)
00060 value = max;
00061 if (value < min)
00062 value = min;
00063 ps = (value - min) / (max - min) * 100;
00064 shx = EXTRADATA(node).texl[0];
00065 shx += round(ps * pointWidth);
00066 }
00067
00068 width = (shx * node->size[0]) / TEXTURE_WIDTH;
00069
00070 UI_DrawNormImageByName(nodepos[0], nodepos[1], width, node->size[1],
00071 shx, EXTRADATA(node).texh[1], EXTRADATA(node).texl[0], EXTRADATA(node).texl[1], ref);
00072 }
00073
00074 static const value_t properties[] = {
00075
00076 {"texh", V_POS, UI_EXTRADATA_OFFSETOF(tbarExtraData_t, texh), MEMBER_SIZEOF(tbarExtraData_t, texh)},
00077
00078 {"texl", V_POS, UI_EXTRADATA_OFFSETOF(tbarExtraData_t, texl), MEMBER_SIZEOF(tbarExtraData_t, texl)},
00079 {NULL, V_NULL, 0, 0}
00080 };
00081
00082 void UI_RegisterTBarNode (uiBehaviour_t *behaviour)
00083 {
00084 behaviour->name = "tbar";
00085 behaviour->extends = "abstractvalue";
00086 behaviour->draw = UI_TBarNodeDraw;
00087 behaviour->properties = properties;
00088 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00089 }