ui_node_rows.c
Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00061 if (EXTRADATA(node).lineHeight == 0) {
00062 EXTRADATA(node).lineHeight = 10;
00063 }
00064 }
00065
00066 static const value_t properties[] = {
00067
00068 {"color1", V_COLOR, offsetof(uiNode_t, color), MEMBER_SIZEOF(uiNode_t, color)},
00069
00070 {"color2", V_COLOR, offsetof(uiNode_t, selectedColor), MEMBER_SIZEOF(uiNode_t, selectedColor)},
00071
00072 {"lineheight", V_INT, UI_EXTRADATA_OFFSETOF(rowsExtraData_t, lineHeight), MEMBER_SIZEOF(rowsExtraData_t, lineHeight)},
00073
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 }