1 /**
2  * @file
3  * @brief Data and interface to share data
4  * @todo clean up the interface
5  */
6 
7 /*
8 Copyright (C) 2002-2013 UFO: Alien Invasion.
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 See the GNU General Public License for more details.
20 
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24 
25 */
26 
27 #pragma once
28 
29 #include "../../shared/ufotypes.h"
30 #include "../../shared/shared.h"
31 #include "ui_nodes.h"
32 #include "node/ui_node_option.h"
33 #include "ui_dataids.h"
34 
35 struct linkedList_t;
36 
37 typedef enum {
38 	UI_SHARED_NONE = 0,
39 	UI_SHARED_TEXT,
40 	UI_SHARED_LINKEDLISTTEXT,
41 	UI_SHARED_OPTION,
42 	UI_SHARED_LINESTRIP
43 } uiSharedType_t;
44 
45 typedef struct uiSharedData_s {
46 	uiSharedType_t type;		/**< Type of the shared data */
47 	union {
48 		/** @brief Holds static array of characters to display */
49 		const char* text;
50 		/** @brief Holds a linked list for displaying in the UI */
51 		linkedList_t* linkedListText;
52 		/** @brief Holds a linked list for option (label, action, icon...) */
53 		uiNode_t* option;
54 		/** @brief Holds a line strip, a list of point */
55 		struct lineStrip_s	*lineStrip;
56 	} data;						/**< The data */
57 	int versionId;				/**< Id identify the value, to check changes */
58 } uiSharedData_t;
59 
60 #define MAX_DEPTH_OPTIONITERATORCACHE 8
61 
62 typedef struct {
63 	uiNode_t* option;		/**< current option */
64 	uiNode_t* depthCache[MAX_DEPTH_OPTIONITERATORCACHE];	/**< parent link */
65 	int depthPos;			/**< current cache position */
66 	bool skipInvisible;		/**< skip invisible options when we iterate */
67 	bool skipCollapsed;		/**< skip collapsed options when we iterate */
68 } uiOptionIterator_t;
69 
70 /* common */
71 int UI_GetDataVersion(int textId) __attribute__ ((warn_unused_result));
72 void UI_ResetData(int dataId);
73 int UI_GetDataIDByName(const char* name) __attribute__ ((warn_unused_result));
74 void UI_InitData(void);
75 
76 /* text */
77 void UI_RegisterText(int textId, const char* text);
78 const char* UI_GetText(int textId) __attribute__ ((warn_unused_result));
79 const char* UI_GetTextFromList(int textId, int line) __attribute__ ((warn_unused_result));
80 
81 /* linked list */
82 void UI_RegisterLinkedListText(int textId, linkedList_t* text);
83 
84 /* option */
85 void UI_RegisterOption(int dataId, uiNode_t* option);
86 uiNode_t* UI_GetOption(int dataId) __attribute__ ((warn_unused_result));
87 void UI_SortOptions(uiNode_t** option);
88 uiNode_t* UI_InitOptionIteratorAtIndex(int index, uiNode_t* option, uiOptionIterator_t* iterator);
89 uiNode_t* UI_OptionIteratorNextOption(uiOptionIterator_t* iterator);
90 void UI_UpdateInvisOptions(uiNode_t* option, const linkedList_t* stringList);
91 uiNode_t* UI_FindOptionByValue(uiOptionIterator_t* iterator, const char* value);
92 int UI_FindOptionPosition(uiOptionIterator_t* iterator, uiNode_t const* option);
93 uiNode_t* UI_AddOption(uiNode_t** tree, const char* name, const char* label, const char* value);
94 
95 /* line strip */
96 void UI_RegisterLineStrip(int dataId, struct lineStrip_s* text);
97