ui_node_tbar.c

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2002-2010 UFO: Alien Invasion.
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 
00017 See the GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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     /* dataImageOrModel is the texture name */
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; /* relative to the texture */
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         /* clamp the value */
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];  /* left gap to the texture */
00065         shx += round(ps * pointWidth); /* add size from 0..TEXTURE_WIDTH */
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     /* @todo Need documentation */
00076     {"texh", V_POS, UI_EXTRADATA_OFFSETOF(tbarExtraData_t, texh), MEMBER_SIZEOF(tbarExtraData_t, texh)},
00077     /* @todo Need documentation */
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 }

Generated by  doxygen 1.6.2