1 /**
2 * @file
3 */
4
5 /*
6 Copyright (C) 2002-2013 UFO: Alien Invasion.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 See the GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 */
24
25 #include "../ui_nodes.h"
26 #include "../ui_parse.h"
27 #include "../ui_internal.h"
28 #include "../ui_render.h"
29 #include "ui_node_abstractnode.h"
30 #include "ui_node_linechart.h"
31
32 #include "../../renderer/r_draw.h"
33
34 #define EXTRADATA_TYPE lineChartExtraData_t
35 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
36
draw(uiNode_t * node)37 void uiLineChartNode::draw (uiNode_t* node)
38 {
39 lineStrip_t* lineStrip;
40 const int dataId = EXTRADATA(node).dataId;
41 vec3_t pos;
42
43 if (dataId == 0)
44 return;
45
46 if (ui_global.sharedData[dataId].type != UI_SHARED_LINESTRIP) {
47 Com_Printf("UI_LineStripNodeDraw: Node '%s' have use an invalide dataId type. LineStrip expected. dataId invalidated\n", UI_GetPath(node));
48 EXTRADATA(node).dataId = 0;
49 return;
50 }
51
52 UI_GetNodeAbsPos(node, pos);
53 pos[2] = 0;
54
55 UI_Transform(pos, nullptr, nullptr);
56
57 /* Draw axes */
58 if (EXTRADATA(node).displayAxes) {
59 int axes[6];
60 axes[0] = 0;
61 axes[1] = 0;
62 axes[2] = 0;
63 axes[3] = (int) node->box.size[1];
64 axes[4] = (int) node->box.size[0];
65 axes[5] = (int) node->box.size[1];
66 R_Color(EXTRADATA(node).axesColor);
67 R_DrawLineStrip(3, axes);
68 }
69
70 /* Draw all linestrips. */
71 lineStrip = ui_global.sharedData[dataId].data.lineStrip;
72 for (; lineStrip; lineStrip = lineStrip->next) {
73 /* Draw this line if it's valid. */
74 if (lineStrip->pointList && lineStrip->numPoints > 0) {
75 R_Color(lineStrip->color);
76 R_DrawLineStrip(lineStrip->numPoints, lineStrip->pointList);
77 }
78 }
79 R_Color(nullptr);
80
81 UI_Transform(nullptr, nullptr, nullptr);
82 }
83
UI_RegisterLineChartNode(uiBehaviour_t * behaviour)84 void UI_RegisterLineChartNode (uiBehaviour_t* behaviour)
85 {
86 behaviour->name = "linechart";
87 behaviour->manager = UINodePtr(new uiLineChartNode());
88 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
89
90 /* Identity the shared data the node use. It must be a LINESTRIP data. */
91 UI_RegisterExtradataNodeProperty(behaviour, "dataid", V_UI_DATAID, lineChartExtraData_t, dataId);
92 /* If true, it display axes of the chart. */
93 UI_RegisterExtradataNodeProperty(behaviour, "displayaxes", V_BOOL, lineChartExtraData_t, displayAxes);
94 /* Axe color. */
95 UI_RegisterExtradataNodeProperty(behaviour, "axescolor", V_COLOR, lineChartExtraData_t, axesColor);
96 }
97