ui_node_rows.c

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018 See the GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 
00024 */
00025 
00026 #include "../ui_render.h"
00027 #include "ui_node_rows.h"
00028 #include "ui_node_abstractnode.h"
00029 
00030 #define EXTRADATA_TYPE rowsExtraData_t
00031 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00032 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
00033 
00037 static void UI_RowsNodeDraw (uiNode_t *node)
00038 {
00039     int current = 0;
00040     int i = EXTRADATA(node).current;
00041     vec2_t pos;
00042     UI_GetNodeAbsPos(node, pos);
00043 
00044     while (current < node->size[1]) {
00045         const float *color;
00046         const int height = min(EXTRADATA(node).lineHeight, node->size[1] - current);
00047 
00048         if (i % 2)
00049             color = node->color;
00050         else
00051             color = node->selectedColor;
00052         UI_DrawFill(pos[0], pos[1] + current, node->size[0], height, color);
00053         current += height;
00054         i++;
00055     }
00056 }
00057 
00058 static void UI_RowsNodeLoaded (uiNode_t *node)
00059 {
00060     /* prevent infinite loop into the draw */
00061     if (EXTRADATA(node).lineHeight == 0) {
00062         EXTRADATA(node).lineHeight = 10;
00063     }
00064 }
00065 
00066 static const value_t properties[] = {
00067     /* Background color for odd elements */
00068     {"color1", V_COLOR, offsetof(uiNode_t, color), MEMBER_SIZEOF(uiNode_t, color)},
00069     /* Background color for even elements */
00070     {"color2", V_COLOR, offsetof(uiNode_t, selectedColor), MEMBER_SIZEOF(uiNode_t, selectedColor)},
00071     /* Element height */
00072     {"lineheight", V_INT, UI_EXTRADATA_OFFSETOF(rowsExtraData_t, lineHeight), MEMBER_SIZEOF(rowsExtraData_t, lineHeight)},
00073     /* Element number on the top of the list. It is used to scroll the node content. */
00074     {"current", V_INT, UI_EXTRADATA_OFFSETOF(rowsExtraData_t, current), MEMBER_SIZEOF(rowsExtraData_t, current)},
00075     {NULL, V_NULL, 0, 0}
00076 };
00077 
00078 void UI_RegisterRowsNode (uiBehaviour_t *behaviour)
00079 {
00080     behaviour->name = "rows";
00081     behaviour->draw = UI_RowsNodeDraw;
00082     behaviour->loaded = UI_RowsNodeLoaded;
00083     behaviour->properties = properties;
00084     behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00085 }

Generated by  doxygen 1.6.2