summaryrefslogtreecommitdiff
path: root/indra/newview/lltoolobjpicker.cpp
blob: ca74a64bf8d8b46f55057688af111db007e82890 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/** 
 * @file lltoolobjpicker.cpp
 * @brief LLToolObjPicker class implementation
 *
 * Copyright (c) 2001-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

// LLToolObjPicker is a transient tool, useful for a single object pick.

#include "llviewerprecompiledheaders.h"

#include "lltoolobjpicker.h"

#include "llagent.h"
#include "llselectmgr.h"
#include "llworld.h"
#include "viewer.h"				// for gFPSClamped, pie menus
#include "llviewercontrol.h"
#include "llmenugl.h"
#include "lltoolmgr.h"
#include "llviewerobject.h"
#include "llviewerobjectlist.h"
#include "llviewermenu.h"
#include "llviewercamera.h"
#include "llviewerwindow.h"
#include "lldrawable.h"

LLToolObjPicker* gToolObjPicker = NULL;

LLToolObjPicker::LLToolObjPicker()
:	LLTool( "ObjPicker", NULL ),
	mPicked( FALSE ),
	mHitObjectID( LLUUID::null ),
	mExitCallback( NULL ),
	mExitCallbackData( NULL )
{ }


// returns TRUE if an object was selected 
BOOL LLToolObjPicker::handleMouseDown(S32 x, S32 y, MASK mask)
{
	LLView* viewp = gViewerWindow->getRootView();
	BOOL handled = viewp->handleMouseDown(x, y, mask);

	mHitObjectID.setNull();

	if (! handled)
	{
		// didn't click in any UI object, so must have clicked in the world
		gViewerWindow->hitObjectOrLandGlobalAsync(x, y, mask, pickCallback);
		handled = TRUE;
	}
	else
	{
		if (hasMouseCapture())
		{
			setMouseCapture(FALSE);
		}
		else
		{
			llwarns << "PickerTool doesn't have mouse capture on mouseDown" << llendl;	
		}
	}

	// Pass mousedown to base class
	LLTool::handleMouseDown(x, y, mask);

	return handled;
}

void LLToolObjPicker::pickCallback(S32 x, S32 y, MASK mask)
{
	// You must hit the body for this tool to think you hit the object.
	LLViewerObject*	objectp = NULL;
	objectp = gObjectList.findObject( gLastHitObjectID );
	if (objectp)
	{
		gToolObjPicker->mHitObjectID = objectp->mID;
		gToolObjPicker->mPicked = TRUE;
	}
}


BOOL LLToolObjPicker::handleMouseUp(S32 x, S32 y, MASK mask)
{
	LLView* viewp = gViewerWindow->getRootView();
	BOOL handled = viewp->handleHover(x, y, mask);
	if (handled)
	{
		// let UI handle this
	}

	LLTool::handleMouseUp(x, y, mask);
	if (hasMouseCapture())
	{
		setMouseCapture(FALSE);
	}
	else
	{
		llwarns << "PickerTool doesn't have mouse capture on mouseUp" << llendl;	
	}
	return handled;
}


BOOL LLToolObjPicker::handleHover(S32 x, S32 y, MASK mask)
{
	LLView *viewp = gViewerWindow->getRootView();
	BOOL handled = viewp->handleHover(x, y, mask);
	if (!handled) 
	{
		// Used to do pick on hover.  Now we just always display the cursor.
		ECursorType cursor = UI_CURSOR_ARROWLOCKED;

		cursor = UI_CURSOR_TOOLPICKOBJECT3;

		gViewerWindow->getWindow()->setCursor(cursor);
	}
	return handled;
}


void LLToolObjPicker::onMouseCaptureLost()
{
	if (mExitCallback)
	{
		mExitCallback(mExitCallbackData);

		mExitCallback = NULL;
		mExitCallbackData = NULL;
	}

	mPicked = FALSE;
	mHitObjectID.setNull();
}

// virtual
void LLToolObjPicker::setExitCallback(void (*callback)(void *), void *callback_data)
{
	mExitCallback = callback;
	mExitCallbackData = callback_data;
}

// virtual
void LLToolObjPicker::handleSelect()
{
	LLTool::handleSelect();
	setMouseCapture(TRUE);
}

// virtual
void LLToolObjPicker::handleDeselect()
{
	if (hasMouseCapture())
	{
		LLTool::handleDeselect();
		setMouseCapture(FALSE);
	}
}