ui_node_zone.c

Go to the documentation of this file.
00001 
00011 /*
00012 Copyright (C) 2002-2010 UFO: Alien Invasion.
00013 
00014 This program is free software; you can redistribute it and/or
00015 modify it under the terms of the GNU General Public License
00016 as published by the Free Software Foundation; either version 2
00017 of the License, or (at your option) any later version.
00018 
00019 This program is distributed in the hope that it will be useful,
00020 but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 
00023 See the GNU General Public License for more details.
00024 
00025 You should have received a copy of the GNU General Public License
00026 along with this program; if not, write to the Free Software
00027 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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     /* If true, the <code>onclick</code> call back is called more than one time if the user do not release the button. */
00104     {"repeat", V_BOOL, UI_EXTRADATA_OFFSETOF(zoneExtraData_t, repeat), MEMBER_SIZEOF(zoneExtraData_t, repeat)},
00105     /* Delay it is used between 2 calls of <code>onclick</code>. */
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 }

Generated by  doxygen 1.6.2