diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llui/llresizebar.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llui/llresizebar.cpp')
-rw-r--r-- | linden/indra/llui/llresizebar.cpp | 276 |
1 files changed, 276 insertions, 0 deletions
diff --git a/linden/indra/llui/llresizebar.cpp b/linden/indra/llui/llresizebar.cpp new file mode 100644 index 0000000..1298b75 --- /dev/null +++ b/linden/indra/llui/llresizebar.cpp | |||
@@ -0,0 +1,276 @@ | |||
1 | /** | ||
2 | * @file llresizebar.cpp | ||
3 | * @brief LLResizeBar base class | ||
4 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "linden_common.h" | ||
29 | |||
30 | #include "llresizebar.h" | ||
31 | |||
32 | //#include "llviewermenu.h" | ||
33 | //#include "llviewerimagelist.h" | ||
34 | #include "llmath.h" | ||
35 | #include "llui.h" | ||
36 | #include "llmenugl.h" | ||
37 | #include "llfocusmgr.h" | ||
38 | #include "llwindow.h" | ||
39 | |||
40 | LLResizeBar::LLResizeBar( const LLString& name, const LLRect& rect, S32 min_width, S32 min_height, Side side ) | ||
41 | : | ||
42 | LLView( name, rect, TRUE ), | ||
43 | mDragStartScreenX( 0 ), | ||
44 | mDragStartScreenY( 0 ), | ||
45 | mLastMouseScreenX( 0 ), | ||
46 | mLastMouseScreenY( 0 ), | ||
47 | mMinWidth( min_width ), | ||
48 | mMinHeight( min_height ), | ||
49 | mSide( side ) | ||
50 | { | ||
51 | // set up some generically good follow code. | ||
52 | switch( side ) | ||
53 | { | ||
54 | case LEFT: | ||
55 | setFollowsLeft(); | ||
56 | setFollowsTop(); | ||
57 | setFollowsBottom(); | ||
58 | break; | ||
59 | case TOP: | ||
60 | setFollowsTop(); | ||
61 | setFollowsLeft(); | ||
62 | setFollowsRight(); | ||
63 | break; | ||
64 | case RIGHT: | ||
65 | setFollowsRight(); | ||
66 | setFollowsTop(); | ||
67 | setFollowsBottom(); | ||
68 | break; | ||
69 | case BOTTOM: | ||
70 | setFollowsBottom(); | ||
71 | setFollowsLeft(); | ||
72 | setFollowsRight(); | ||
73 | break; | ||
74 | default: | ||
75 | break; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | |||
80 | BOOL LLResizeBar::handleMouseDown(S32 x, S32 y, MASK mask) | ||
81 | { | ||
82 | if( mEnabled ) | ||
83 | { | ||
84 | // Route future Mouse messages here preemptively. (Release on mouse up.) | ||
85 | // No handler needed for focus lost since this clas has no state that depends on it. | ||
86 | gFocusMgr.setMouseCapture( this, NULL ); | ||
87 | |||
88 | //localPointToScreen(x, y, &mDragStartScreenX, &mDragStartScreenX); | ||
89 | localPointToOtherView(x, y, &mDragStartScreenX, &mDragStartScreenY, getParent()->getParent()); | ||
90 | mLastMouseScreenX = mDragStartScreenX; | ||
91 | mLastMouseScreenY = mDragStartScreenY; | ||
92 | } | ||
93 | |||
94 | return TRUE; | ||
95 | } | ||
96 | |||
97 | |||
98 | BOOL LLResizeBar::handleMouseUp(S32 x, S32 y, MASK mask) | ||
99 | { | ||
100 | BOOL handled = FALSE; | ||
101 | |||
102 | if( gFocusMgr.getMouseCapture() == this ) | ||
103 | { | ||
104 | // Release the mouse | ||
105 | gFocusMgr.setMouseCapture( NULL, NULL ); | ||
106 | handled = TRUE; | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | handled = TRUE; | ||
111 | } | ||
112 | return handled; | ||
113 | } | ||
114 | |||
115 | EWidgetType LLResizeBar::getWidgetType() const | ||
116 | { | ||
117 | return WIDGET_TYPE_RESIZE_BAR; | ||
118 | } | ||
119 | |||
120 | LLString LLResizeBar::getWidgetTag() const | ||
121 | { | ||
122 | return LL_RESIZE_BAR_TAG; | ||
123 | } | ||
124 | |||
125 | BOOL LLResizeBar::handleHover(S32 x, S32 y, MASK mask) | ||
126 | { | ||
127 | BOOL handled = FALSE; | ||
128 | |||
129 | // We only handle the click if the click both started and ended within us | ||
130 | if( gFocusMgr.getMouseCapture() == this ) | ||
131 | { | ||
132 | // *NOTE: this, of course, is fragile | ||
133 | LLView* floater_view = getParent()->getParent(); | ||
134 | S32 floater_view_x; | ||
135 | S32 floater_view_y; | ||
136 | localPointToOtherView(x, y, &floater_view_x, &floater_view_y, floater_view); | ||
137 | |||
138 | S32 delta_x = floater_view_x - mDragStartScreenX; | ||
139 | S32 delta_y = floater_view_y - mDragStartScreenY; | ||
140 | |||
141 | LLCoordGL mouse_dir; | ||
142 | // use hysteresis on mouse motion to preserve user intent when mouse stops moving | ||
143 | mouse_dir.mX = (floater_view_x == mLastMouseScreenX) ? mLastMouseDir.mX : floater_view_x - mLastMouseScreenX; | ||
144 | mouse_dir.mY = (floater_view_y == mLastMouseScreenY) ? mLastMouseDir.mY : floater_view_y - mLastMouseScreenY; | ||
145 | mLastMouseDir = mouse_dir; | ||
146 | mLastMouseScreenX = floater_view_x; | ||
147 | mLastMouseScreenY = floater_view_y; | ||
148 | |||
149 | // Make sure the mouse in still over the application. We don't want to make the parent | ||
150 | // so big that we can't see the resize handle any more. | ||
151 | LLRect valid_rect = floater_view->getRect(); | ||
152 | LLView* parentView = getParent(); | ||
153 | if( valid_rect.localPointInRect( floater_view_x, floater_view_y ) && parentView ) | ||
154 | { | ||
155 | // Resize the parent | ||
156 | LLRect parent_rect = parentView->getRect(); | ||
157 | LLRect scaled_rect = parent_rect; | ||
158 | |||
159 | S32 new_width = parent_rect.getWidth(); | ||
160 | S32 new_height = parent_rect.getHeight(); | ||
161 | |||
162 | switch( mSide ) | ||
163 | { | ||
164 | case LEFT: | ||
165 | new_width = parent_rect.getWidth() - delta_x; | ||
166 | if( new_width < mMinWidth ) | ||
167 | { | ||
168 | new_width = mMinWidth; | ||
169 | delta_x = parent_rect.getWidth() - mMinWidth; | ||
170 | } | ||
171 | scaled_rect.translate(delta_x, 0); | ||
172 | break; | ||
173 | |||
174 | case TOP: | ||
175 | new_height = parent_rect.getHeight() + delta_y; | ||
176 | if( new_height < mMinHeight ) | ||
177 | { | ||
178 | new_height = mMinHeight; | ||
179 | delta_y = mMinHeight - parent_rect.getHeight(); | ||
180 | } | ||
181 | break; | ||
182 | |||
183 | case RIGHT: | ||
184 | new_width = parent_rect.getWidth() + delta_x; | ||
185 | if( new_width < mMinWidth ) | ||
186 | { | ||
187 | new_width = mMinWidth; | ||
188 | delta_x = mMinWidth - parent_rect.getWidth(); | ||
189 | } | ||
190 | break; | ||
191 | |||
192 | case BOTTOM: | ||
193 | new_height = parent_rect.getHeight() - delta_y; | ||
194 | if( new_height < mMinHeight ) | ||
195 | { | ||
196 | new_height = mMinHeight; | ||
197 | delta_y = parent_rect.getHeight() - mMinHeight; | ||
198 | } | ||
199 | scaled_rect.translate(0, delta_y); | ||
200 | break; | ||
201 | } | ||
202 | |||
203 | scaled_rect.mTop = scaled_rect.mBottom + new_height; | ||
204 | scaled_rect.mRight = scaled_rect.mLeft + new_width; | ||
205 | parentView->setRect(scaled_rect); | ||
206 | |||
207 | S32 snap_delta_x = 0; | ||
208 | S32 snap_delta_y = 0; | ||
209 | |||
210 | LLView* snap_view = NULL; | ||
211 | |||
212 | switch( mSide ) | ||
213 | { | ||
214 | case LEFT: | ||
215 | snap_view = parentView->findSnapEdge(snap_delta_x, mouse_dir, SNAP_LEFT, SNAP_PARENT_AND_SIBLINGS, LLUI::sConfigGroup->getS32("SnapMargin")); | ||
216 | snap_delta_x -= scaled_rect.mLeft; | ||
217 | scaled_rect.mLeft += snap_delta_x; | ||
218 | break; | ||
219 | case TOP: | ||
220 | snap_view = parentView->findSnapEdge(snap_delta_y, mouse_dir, SNAP_TOP, SNAP_PARENT_AND_SIBLINGS, LLUI::sConfigGroup->getS32("SnapMargin")); | ||
221 | snap_delta_y -= scaled_rect.mTop; | ||
222 | scaled_rect.mTop += snap_delta_y; | ||
223 | break; | ||
224 | case RIGHT: | ||
225 | snap_view = parentView->findSnapEdge(snap_delta_x, mouse_dir, SNAP_RIGHT, SNAP_PARENT_AND_SIBLINGS, LLUI::sConfigGroup->getS32("SnapMargin")); | ||
226 | snap_delta_x -= scaled_rect.mRight; | ||
227 | scaled_rect.mRight += snap_delta_x; | ||
228 | break; | ||
229 | case BOTTOM: | ||
230 | snap_view = parentView->findSnapEdge(snap_delta_y, mouse_dir, SNAP_BOTTOM, SNAP_PARENT_AND_SIBLINGS, LLUI::sConfigGroup->getS32("SnapMargin")); | ||
231 | snap_delta_y -= scaled_rect.mBottom; | ||
232 | scaled_rect.mBottom += snap_delta_y; | ||
233 | break; | ||
234 | } | ||
235 | |||
236 | parentView->snappedTo(snap_view); | ||
237 | |||
238 | parentView->setRect(parent_rect); | ||
239 | |||
240 | parentView->reshape(scaled_rect.getWidth(), scaled_rect.getHeight(), FALSE); | ||
241 | parentView->translate(scaled_rect.mLeft - parentView->getRect().mLeft, scaled_rect.mBottom - parentView->getRect().mBottom); | ||
242 | |||
243 | floater_view_x = mDragStartScreenX + delta_x; | ||
244 | floater_view_y = mDragStartScreenY + delta_y; | ||
245 | mDragStartScreenX = floater_view_x + snap_delta_x; | ||
246 | mDragStartScreenY = floater_view_y + snap_delta_y; | ||
247 | } | ||
248 | |||
249 | lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; | ||
250 | handled = TRUE; | ||
251 | } | ||
252 | else | ||
253 | { | ||
254 | lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (inactive)" << llendl; | ||
255 | handled = TRUE; | ||
256 | } | ||
257 | |||
258 | if( handled ) | ||
259 | { | ||
260 | switch( mSide ) | ||
261 | { | ||
262 | case LEFT: | ||
263 | case RIGHT: | ||
264 | getWindow()->setCursor(UI_CURSOR_SIZEWE); | ||
265 | break; | ||
266 | |||
267 | case TOP: | ||
268 | case BOTTOM: | ||
269 | getWindow()->setCursor(UI_CURSOR_SIZENS); | ||
270 | break; | ||
271 | } | ||
272 | } | ||
273 | |||
274 | return handled; | ||
275 | } | ||
276 | |||