ui_node_controls.c

Go to the documentation of this file.
00001 
00008 /*
00009 Copyright (C) 2002-2010 UFO: Alien Invasion.
00010 
00011 This program is free software; you can redistribute it and/or
00012 modify it under the terms of the GNU General Public License
00013 as published by the Free Software Foundation; either version 2
00014 of the License, or (at your option) any later version.
00015 
00016 This program is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00019 
00020 See the GNU General Public License for more details.
00021 
00022 You should have received a copy of the GNU General Public License
00023 along with this program; if not, write to the Free Software
00024 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00025 
00026 */
00027 
00028 #include "../ui_nodes.h"
00029 #include "../ui_parse.h"
00030 #include "../ui_input.h"
00031 #include "../ui_main.h"
00032 #include "ui_node_image.h"
00033 #include "ui_node_controls.h"
00034 #include "ui_node_abstractnode.h"
00035 
00036 #include "../../input/cl_keys.h"
00037 #include "../../cl_video.h"
00038 
00039 static int deltaMouseX;
00040 static int deltaMouseY;
00041 
00042 static void UI_ControlsNodeMouseDown (uiNode_t *node, int x, int y, int button)
00043 {
00044     if (button == K_MOUSE1) {
00045         UI_SetMouseCapture(node);
00046 
00047         /* save position between mouse and node pos */
00048         UI_NodeAbsoluteToRelativePos(node, &x, &y);
00049         deltaMouseX = x + node->pos[0];
00050         deltaMouseY = y + node->pos[1];
00051     }
00052 }
00053 
00054 static void UI_ControlsNodeMouseUp (uiNode_t *node, int x, int y, int button)
00055 {
00056     if (button == K_MOUSE1)
00057         UI_MouseRelease();
00058 }
00059 
00063 static void UI_ControlsNodeCapturedMouseMove (uiNode_t *node, int x, int y)
00064 {
00065     /* compute new x position of the window */
00066     x -= deltaMouseX;
00067     if (x < 0)
00068         x = 0;
00069     if (x + node->root->size[0] > viddef.virtualWidth)
00070         x = viddef.virtualWidth - node->root->size[0];
00071 
00072     /* compute new y position of the window */
00073     y -= deltaMouseY;
00074     if (y < 0)
00075         y = 0;
00076     if (y + node->root->size[1] > viddef.virtualHeight)
00077         y = viddef.virtualHeight - node->root->size[1];
00078 
00079     UI_SetNewWindowPos(node->root, x, y);
00080 }
00081 
00082 void UI_RegisterControlsNode (uiBehaviour_t *behaviour)
00083 {
00084     behaviour->name = "controls";
00085     behaviour->extends = "image";
00086     behaviour->mouseDown = UI_ControlsNodeMouseDown;
00087     behaviour->mouseUp = UI_ControlsNodeMouseUp;
00088     behaviour->capturedMouseMove = UI_ControlsNodeCapturedMouseMove;
00089 }

Generated by  doxygen 1.6.2