ui_node_zone.c
Go to the documentation of this file.00001
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "../ui_nodes.h"
00032 #include "../ui_parse.h"
00033 #include "../ui_input.h"
00034 #include "../ui_timer.h"
00035 #include "../ui_actions.h"
00036 #include "ui_node_zone.h"
00037 #include "ui_node_window.h"
00038
00039 #include "../../input/cl_keys.h"
00040
00041 #define EXTRADATA_TYPE zoneExtraData_t
00042 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
00043
00044 static uiTimer_t *capturedTimer;
00045
00046 static void UI_ZoneNodeRepeat (uiNode_t *node, uiTimer_t *timer)
00047 {
00048 if (node->onClick) {
00049 UI_ExecuteEventActions(node, node->onClick);
00050 }
00051 }
00052
00053 static void UI_ZoneNodeDown (uiNode_t *node, int x, int y, int button)
00054 {
00055 if (!EXTRADATA(node).repeat)
00056 return;
00057 if (button == K_MOUSE1) {
00058 UI_SetMouseCapture(node);
00059 capturedTimer = UI_AllocTimer(node, EXTRADATA(node).clickDelay, UI_ZoneNodeRepeat);
00060 UI_TimerStart(capturedTimer);
00061 }
00062 }
00063
00064 static void UI_ZoneNodeUp (uiNode_t *node, int x, int y, int button)
00065 {
00066 if (!EXTRADATA(node).repeat)
00067 return;
00068 if (button == K_MOUSE1) {
00069 UI_MouseRelease();
00070 }
00071 }
00072
00077 static void UI_ZoneNodeCapturedMouseLost (uiNode_t *node)
00078 {
00079 if (capturedTimer) {
00080 UI_TimerRelease(capturedTimer);
00081 capturedTimer = NULL;
00082 }
00083 }
00084
00088 static void UI_ZoneNodeLoading (uiNode_t *node)
00089 {
00090 EXTRADATA(node).clickDelay = 1000;
00091 }
00092
00096 static void UI_ZoneNodeLoaded (uiNode_t *node)
00097 {
00098 if (!strcmp(node->name, "render"))
00099 UI_WindowNodeSetRenderNode(node->root, node);
00100 }
00101
00102 static const value_t properties[] = {
00103
00104 {"repeat", V_BOOL, UI_EXTRADATA_OFFSETOF(zoneExtraData_t, repeat), MEMBER_SIZEOF(zoneExtraData_t, repeat)},
00105
00106 {"clickdelay", V_INT, UI_EXTRADATA_OFFSETOF(zoneExtraData_t, clickDelay), MEMBER_SIZEOF(zoneExtraData_t, clickDelay)},
00107 {NULL, V_NULL, 0, 0}
00108 };
00109
00110 void UI_RegisterZoneNode (uiBehaviour_t *behaviour)
00111 {
00112 behaviour->name = "zone";
00113 behaviour->loading = UI_ZoneNodeLoading;
00114 behaviour->loaded = UI_ZoneNodeLoaded;
00115 behaviour->mouseDown = UI_ZoneNodeDown;
00116 behaviour->mouseUp = UI_ZoneNodeUp;
00117 behaviour->capturedMouseLost = UI_ZoneNodeCapturedMouseLost;
00118 behaviour->properties = properties;
00119 behaviour->extraDataSize = sizeof(EXTRADATA_TYPE);
00120 }