00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "../ui_main.h"
00027 #include "../ui_internal.h"
00028 #include "../ui_parse.h"
00029 #include "../ui_draw.h"
00030 #include "../ui_data.h"
00031 #include "ui_node_abstractoption.h"
00032 #include "ui_node_abstractnode.h"
00033
00034 #define EXTRADATA_TYPE abstractOptionExtraData_t
00035 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00036
00037 const uiBehaviour_t *abstractOptionBehaviour;
00038
00042 void UI_OptionNodeSortOptions (uiNode_t *node)
00043 {
00044 uiNode_t *option;
00045 assert(UI_NodeInstanceOf(node, "abstractoption"));
00046 UI_SortOptions(&node->firstChild);
00047
00050 option = node->firstChild;
00051 while (option->next)
00052 option = option->next;
00053 node->lastChild = option;
00054 }
00055
00056 const char *UI_AbstractOptionGetCurrentValue (uiNode_t * node)
00057 {
00058
00059 if (!(EXTRADATA(node).cvar) || !*(char*)(EXTRADATA(node).cvar)) {
00060 Com_Printf("UI_AbstractOptionGetCurrentValue: node '%s' doesn't have a valid cvar assigned\n", UI_GetPath(node));
00061 return NULL;
00062 }
00063
00064
00065 if (strncmp((const char *)(EXTRADATA(node).cvar), "*cvar", 5))
00066 return NULL;
00067
00068 return UI_GetReferenceString(node, (EXTRADATA(node).cvar));
00069 }
00070
00071 void UI_AbstractOptionSetCurrentValue(uiNode_t * node, const char *value)
00072 {
00073 const char *cvarName = &((const char *)(EXTRADATA(node).cvar))[6];
00074 UI_SetCvar(cvarName, value, 0);
00075 if (node->onChange)
00076 UI_ExecuteEventActions(node, node->onChange);
00077 }
00078
00079 static const value_t properties[] = {
00081 {"dataid", V_UI_DATAID, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, dataId), MEMBER_SIZEOF(EXTRADATA_TYPE, dataId)},
00083 {"lineheight", V_INT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, lineHeight), MEMBER_SIZEOF(EXTRADATA_TYPE, lineHeight)},
00084
00085
00086 {"viewpos", V_INT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, scrollY.viewPos), MEMBER_SIZEOF(EXTRADATA_TYPE, scrollY.viewPos)},
00087
00088 {"viewsize", V_INT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, scrollY.viewSize), MEMBER_SIZEOF(EXTRADATA_TYPE, scrollY.viewSize)},
00089
00090 {"fullsize", V_INT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, scrollY.fullSize), MEMBER_SIZEOF(EXTRADATA_TYPE, scrollY.fullSize)},
00091
00092
00093 {"count", V_INT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, count), MEMBER_SIZEOF(EXTRADATA_TYPE, count)},
00094
00095
00096 {"cvar", V_UI_CVAR, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, cvar), 0},
00097
00098
00099 {"onviewchange", V_UI_ACTION, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, onViewChange), MEMBER_SIZEOF(EXTRADATA_TYPE, onViewChange)},
00100
00101 {NULL, V_NULL, 0, 0}
00102 };
00103
00104 static void UI_AbstractOptionDoLayout (uiNode_t *node) {
00105 uiNode_t *option = node->firstChild;
00106
00107 if (EXTRADATA(node).dataId == 0) {
00108 int count = 0;
00109 while(option && option->behaviour == ui_optionBehaviour) {
00110 UI_Validate(option);
00111 if (!option->invis)
00112 count++;
00113 option = option->next;
00114 }
00115
00116 EXTRADATA(node).count = count;
00117 }
00118
00119 node->invalidated = qfalse;
00120 }
00121
00126 uiNode_t* UI_AbstractOptionGetFirstOption (uiNode_t * node)
00127 {
00128 if (node->firstChild && node->firstChild->behaviour == ui_optionBehaviour) {
00129 return node->firstChild;
00130 } else {
00131 const int v = UI_GetDataVersion(EXTRADATA(node).dataId);
00132 if (v != EXTRADATA(node).dataId) {
00133 int count = 0;
00134 uiNode_t *option = UI_GetOption(EXTRADATA(node).dataId);
00135 while (option) {
00136 if (option->invis == qfalse)
00137 count++;
00138 option = option->next;
00139 }
00140 EXTRADATA(node).count = count;
00141 EXTRADATA(node).versionId = v;
00142 }
00143 return UI_GetOption(EXTRADATA(node).dataId);
00144 }
00145 }
00146
00147 void UI_RegisterAbstractOptionNode (uiBehaviour_t *behaviour)
00148 {
00149 behaviour->name = "abstractoption";
00150 behaviour->isAbstract = qtrue;
00151 behaviour->properties = properties;
00152 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00153 behaviour->drawItselfChild = qtrue;
00154 behaviour->doLayout = UI_AbstractOptionDoLayout;
00155 abstractOptionBehaviour = behaviour;
00156 }