ui_node_controls.c
Go to the documentation of this file.00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
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
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 }