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_parse.h"
00028 #include "../ui_font.h"
00029 #include "../ui_render.h"
00030 #include "../ui_actions.h"
00031 #include "ui_node_abstractnode.h"
00032 #include "ui_node_abstractscrollable.h"
00033
00034 #include "../../client.h"
00035
00036 #define EXTRADATA_TYPE abstractScrollableExtraData_t
00037 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00038
00042 qboolean UI_AbstractScrollableNodeIsSizeChange (uiNode_t *node)
00043 {
00044 assert(UI_NodeInstanceOf(node, "abstractscrollable"));
00045
00046 if (node->size[0] != EXTRADATA(node).cacheSize[0]
00047 || node->size[1] != EXTRADATA(node).cacheSize[1])
00048 {
00049 EXTRADATA(node).cacheSize[0] = node->size[0];
00050 EXTRADATA(node).cacheSize[1] = node->size[1];
00051 return qtrue;
00052 }
00053 return qfalse;
00054 }
00055
00064 qboolean UI_SetScroll (uiScroll_t *scroll, int viewPos, int viewSize, int fullSize)
00065 {
00066 qboolean updated = qfalse;
00067
00068
00069 if (viewPos == -1)
00070 viewPos = scroll->viewPos;
00071 if (viewSize == -1)
00072 viewSize = scroll->viewSize;
00073 if (fullSize == -1)
00074 fullSize = scroll->fullSize;
00075
00076
00077 if (viewSize < 0)
00078 viewSize = 0;
00079 if (fullSize < 0)
00080 fullSize = 0;
00081 if (viewPos < 0)
00082 viewPos = 0;
00083
00084
00085 if (viewSize >= fullSize)
00086 viewPos = 0;
00087 else if (viewPos > fullSize - viewSize)
00088 viewPos = fullSize - viewSize;
00089
00090
00091 if (scroll->viewPos != viewPos) {
00092 scroll->viewPos = viewPos;
00093 updated = qtrue;
00094 }
00095 if (scroll->viewSize != viewSize) {
00096 scroll->viewSize = viewSize;
00097 updated = qtrue;
00098 }
00099 if (scroll->fullSize != fullSize) {
00100 scroll->fullSize = fullSize;
00101 updated = qtrue;
00102 }
00103
00104 return updated;
00105 }
00106
00115 qboolean UI_AbstractScrollableNodeSetY (uiNode_t *node, int viewPos, int viewSize, int fullSize)
00116 {
00117 qboolean updated;
00118 assert(UI_NodeInstanceOf(node, "abstractscrollable"));
00119
00120 updated = UI_SetScroll(&EXTRADATA(node).scrollY, viewPos, viewSize, fullSize);
00121
00122 if (updated && EXTRADATA(node).onViewChange)
00123 UI_ExecuteEventActions(node, EXTRADATA(node).onViewChange);
00124
00125 return updated;
00126 }
00127
00131 static void UI_AbstractScrollableNodePageUp (uiNode_t *node, const uiCallContext_t *context) {
00132 const int pos = EXTRADATA(node).scrollY.viewPos - 10;
00133 UI_AbstractScrollableNodeSetY(node, (pos >= 0)?pos:0, -1, -1);
00134 }
00135
00136 static void UI_AbstractScrollableNodePageDown (uiNode_t *node, const uiCallContext_t *context) {
00137 UI_AbstractScrollableNodeSetY(node, EXTRADATA(node).scrollY.viewPos + 10, -1, -1);
00138 }
00139
00140 static void UI_AbstractScrollableNodeMoveUp (uiNode_t *node, const uiCallContext_t *context) {
00141 UI_AbstractScrollableNodeSetY(node, EXTRADATA(node).scrollY.viewPos - 1, -1, -1);
00142 }
00143
00144 static void UI_AbstractScrollableNodeMoveDown (uiNode_t *node, const uiCallContext_t *context) {
00145 UI_AbstractScrollableNodeSetY(node, EXTRADATA(node).scrollY.viewPos + 1, -1, -1);
00146 }
00147
00148 static void UI_AbstractScrollableNodeMoveHome (uiNode_t *node, const uiCallContext_t *context) {
00149 UI_AbstractScrollableNodeSetY(node, 0, -1, -1);
00150 }
00151
00155 static void UI_AbstractScrollableNodeMoveEnd (uiNode_t *node, const uiCallContext_t *context) {
00156 UI_AbstractScrollableNodeSetY(node, EXTRADATA(node).scrollY.fullSize, -1, -1);
00157 }
00158
00163 qboolean UI_AbstractScrollableNodeScrollY (uiNode_t *node, int offset)
00164 {
00165 assert(UI_NodeInstanceOf(node, "abstractscrollable"));
00166 return UI_AbstractScrollableNodeSetY(node, EXTRADATA(node).scrollY.viewPos + offset, -1, -1);
00167 }
00168
00169 static const value_t properties[] = {
00170
00171 {"viewpos", V_INT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, scrollY.viewPos), MEMBER_SIZEOF(EXTRADATA_TYPE, scrollY.viewPos)},
00172
00173 {"viewsize", V_INT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, scrollY.viewSize), MEMBER_SIZEOF(EXTRADATA_TYPE, scrollY.viewSize)},
00174
00175 {"fullsize", V_INT, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, scrollY.fullSize), MEMBER_SIZEOF(EXTRADATA_TYPE, scrollY.fullSize)},
00176
00177 {"onviewchange", V_UI_ACTION, UI_EXTRADATA_OFFSETOF(EXTRADATA_TYPE, onViewChange), MEMBER_SIZEOF(EXTRADATA_TYPE, onViewChange)},
00178
00179
00180 {"pageup", V_UI_NODEMETHOD, ((size_t) UI_AbstractScrollableNodePageUp), 0},
00181
00182 {"pagedown", V_UI_NODEMETHOD, ((size_t) UI_AbstractScrollableNodePageDown), 0},
00183
00184 {"moveup", V_UI_NODEMETHOD, ((size_t) UI_AbstractScrollableNodeMoveUp), 0},
00185
00186 {"movedown", V_UI_NODEMETHOD, ((size_t) UI_AbstractScrollableNodeMoveDown), 0},
00187
00188 {"movehome", V_UI_NODEMETHOD, ((size_t) UI_AbstractScrollableNodeMoveHome), 0},
00189
00190 {"moveend", V_UI_NODEMETHOD, ((size_t) UI_AbstractScrollableNodeMoveEnd), 0},
00191
00192 {NULL, V_NULL, 0, 0}
00193 };
00194
00195 void UI_RegisterAbstractScrollableNode (uiBehaviour_t *behaviour)
00196 {
00197 behaviour->name = "abstractscrollable";
00198 behaviour->isAbstract = qtrue;
00199 behaviour->properties = properties;
00200 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00201 }