diff options
author | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
commit | b2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch) | |
tree | 3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/llui/llresizebar.cpp | |
parent | Second Life viewer sources 1.14.0.1 (diff) | |
download | meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.zip meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.gz meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.bz2 meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.xz |
Second Life viewer sources 1.15.0.2
Diffstat (limited to 'linden/indra/llui/llresizebar.cpp')
-rw-r--r-- | linden/indra/llui/llresizebar.cpp | 130 |
1 files changed, 67 insertions, 63 deletions
diff --git a/linden/indra/llui/llresizebar.cpp b/linden/indra/llui/llresizebar.cpp index 1298b75..79127a8 100644 --- a/linden/indra/llui/llresizebar.cpp +++ b/linden/indra/llui/llresizebar.cpp | |||
@@ -4,6 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | 5 | * Copyright (c) 2001-2007, Linden Research, Inc. |
6 | * | 6 | * |
7 | * Second Life Viewer Source Code | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | 8 | * 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 | * 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 | * ("GPL"), unless you have obtained a separate licensing agreement |
@@ -40,8 +41,8 @@ | |||
40 | LLResizeBar::LLResizeBar( const LLString& name, const LLRect& rect, S32 min_width, S32 min_height, Side side ) | 41 | LLResizeBar::LLResizeBar( const LLString& name, const LLRect& rect, S32 min_width, S32 min_height, Side side ) |
41 | : | 42 | : |
42 | LLView( name, rect, TRUE ), | 43 | LLView( name, rect, TRUE ), |
43 | mDragStartScreenX( 0 ), | 44 | mDragLastScreenX( 0 ), |
44 | mDragStartScreenY( 0 ), | 45 | mDragLastScreenY( 0 ), |
45 | mLastMouseScreenX( 0 ), | 46 | mLastMouseScreenX( 0 ), |
46 | mLastMouseScreenY( 0 ), | 47 | mLastMouseScreenY( 0 ), |
47 | mMinWidth( min_width ), | 48 | mMinWidth( min_width ), |
@@ -74,6 +75,8 @@ LLResizeBar::LLResizeBar( const LLString& name, const LLRect& rect, S32 min_widt | |||
74 | default: | 75 | default: |
75 | break; | 76 | break; |
76 | } | 77 | } |
78 | // this is just a decorator | ||
79 | setSaveToXML(FALSE); | ||
77 | } | 80 | } |
78 | 81 | ||
79 | 82 | ||
@@ -83,12 +86,11 @@ BOOL LLResizeBar::handleMouseDown(S32 x, S32 y, MASK mask) | |||
83 | { | 86 | { |
84 | // Route future Mouse messages here preemptively. (Release on mouse up.) | 87 | // 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. | 88 | // No handler needed for focus lost since this clas has no state that depends on it. |
86 | gFocusMgr.setMouseCapture( this, NULL ); | 89 | gFocusMgr.setMouseCapture( this ); |
87 | 90 | ||
88 | //localPointToScreen(x, y, &mDragStartScreenX, &mDragStartScreenX); | 91 | localPointToScreen(x, y, &mDragLastScreenX, &mDragLastScreenY); |
89 | localPointToOtherView(x, y, &mDragStartScreenX, &mDragStartScreenY, getParent()->getParent()); | 92 | mLastMouseScreenX = mDragLastScreenX; |
90 | mLastMouseScreenX = mDragStartScreenX; | 93 | mLastMouseScreenY = mDragLastScreenY; |
91 | mLastMouseScreenY = mDragStartScreenY; | ||
92 | } | 94 | } |
93 | 95 | ||
94 | return TRUE; | 96 | return TRUE; |
@@ -99,10 +101,10 @@ BOOL LLResizeBar::handleMouseUp(S32 x, S32 y, MASK mask) | |||
99 | { | 101 | { |
100 | BOOL handled = FALSE; | 102 | BOOL handled = FALSE; |
101 | 103 | ||
102 | if( gFocusMgr.getMouseCapture() == this ) | 104 | if( hasMouseCapture() ) |
103 | { | 105 | { |
104 | // Release the mouse | 106 | // Release the mouse |
105 | gFocusMgr.setMouseCapture( NULL, NULL ); | 107 | gFocusMgr.setMouseCapture( NULL ); |
106 | handled = TRUE; | 108 | handled = TRUE; |
107 | } | 109 | } |
108 | else | 110 | else |
@@ -127,74 +129,73 @@ BOOL LLResizeBar::handleHover(S32 x, S32 y, MASK mask) | |||
127 | BOOL handled = FALSE; | 129 | BOOL handled = FALSE; |
128 | 130 | ||
129 | // We only handle the click if the click both started and ended within us | 131 | // We only handle the click if the click both started and ended within us |
130 | if( gFocusMgr.getMouseCapture() == this ) | 132 | if( hasMouseCapture() ) |
131 | { | 133 | { |
132 | // *NOTE: this, of course, is fragile | 134 | S32 screen_x; |
133 | LLView* floater_view = getParent()->getParent(); | 135 | S32 screen_y; |
134 | S32 floater_view_x; | 136 | localPointToScreen(x, y, &screen_x, &screen_y); |
135 | S32 floater_view_y; | ||
136 | localPointToOtherView(x, y, &floater_view_x, &floater_view_y, floater_view); | ||
137 | 137 | ||
138 | S32 delta_x = floater_view_x - mDragStartScreenX; | 138 | S32 delta_x = screen_x - mDragLastScreenX; |
139 | S32 delta_y = floater_view_y - mDragStartScreenY; | 139 | S32 delta_y = screen_y - mDragLastScreenY; |
140 | 140 | ||
141 | LLCoordGL mouse_dir; | 141 | LLCoordGL mouse_dir; |
142 | // use hysteresis on mouse motion to preserve user intent when mouse stops moving | 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; | 143 | mouse_dir.mX = (screen_x == mLastMouseScreenX) ? mLastMouseDir.mX : screen_x - mLastMouseScreenX; |
144 | mouse_dir.mY = (floater_view_y == mLastMouseScreenY) ? mLastMouseDir.mY : floater_view_y - mLastMouseScreenY; | 144 | mouse_dir.mY = (screen_y == mLastMouseScreenY) ? mLastMouseDir.mY : screen_y - mLastMouseScreenY; |
145 | mLastMouseDir = mouse_dir; | 145 | mLastMouseDir = mouse_dir; |
146 | mLastMouseScreenX = floater_view_x; | 146 | mLastMouseScreenX = screen_x; |
147 | mLastMouseScreenY = floater_view_y; | 147 | mLastMouseScreenY = screen_y; |
148 | 148 | ||
149 | // Make sure the mouse in still over the application. We don't want to make the parent | 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. | 150 | // so big that we can't see the resize handle any more. |
151 | LLRect valid_rect = floater_view->getRect(); | 151 | LLRect valid_rect = getRootView()->getRect(); |
152 | LLView* parentView = getParent(); | 152 | LLView* resizing_view = getParent(); |
153 | if( valid_rect.localPointInRect( floater_view_x, floater_view_y ) && parentView ) | 153 | |
154 | if( valid_rect.localPointInRect( screen_x, screen_y ) && resizing_view ) | ||
154 | { | 155 | { |
155 | // Resize the parent | 156 | // Resize the parent |
156 | LLRect parent_rect = parentView->getRect(); | 157 | LLRect orig_rect = resizing_view->getRect(); |
157 | LLRect scaled_rect = parent_rect; | 158 | LLRect scaled_rect = orig_rect; |
158 | 159 | ||
159 | S32 new_width = parent_rect.getWidth(); | 160 | S32 new_width = orig_rect.getWidth(); |
160 | S32 new_height = parent_rect.getHeight(); | 161 | S32 new_height = orig_rect.getHeight(); |
161 | 162 | ||
162 | switch( mSide ) | 163 | switch( mSide ) |
163 | { | 164 | { |
164 | case LEFT: | 165 | case LEFT: |
165 | new_width = parent_rect.getWidth() - delta_x; | 166 | new_width = orig_rect.getWidth() - delta_x; |
166 | if( new_width < mMinWidth ) | 167 | if( new_width < mMinWidth ) |
167 | { | 168 | { |
168 | new_width = mMinWidth; | 169 | new_width = mMinWidth; |
169 | delta_x = parent_rect.getWidth() - mMinWidth; | 170 | delta_x = orig_rect.getWidth() - mMinWidth; |
170 | } | 171 | } |
171 | scaled_rect.translate(delta_x, 0); | 172 | scaled_rect.translate(delta_x, 0); |
172 | break; | 173 | break; |
173 | 174 | ||
174 | case TOP: | 175 | case TOP: |
175 | new_height = parent_rect.getHeight() + delta_y; | 176 | new_height = orig_rect.getHeight() + delta_y; |
176 | if( new_height < mMinHeight ) | 177 | if( new_height < mMinHeight ) |
177 | { | 178 | { |
178 | new_height = mMinHeight; | 179 | new_height = mMinHeight; |
179 | delta_y = mMinHeight - parent_rect.getHeight(); | 180 | delta_y = mMinHeight - orig_rect.getHeight(); |
180 | } | 181 | } |
181 | break; | 182 | break; |
182 | 183 | ||
183 | case RIGHT: | 184 | case RIGHT: |
184 | new_width = parent_rect.getWidth() + delta_x; | 185 | new_width = orig_rect.getWidth() + delta_x; |
185 | if( new_width < mMinWidth ) | 186 | if( new_width < mMinWidth ) |
186 | { | 187 | { |
187 | new_width = mMinWidth; | 188 | new_width = mMinWidth; |
188 | delta_x = mMinWidth - parent_rect.getWidth(); | 189 | delta_x = mMinWidth - orig_rect.getWidth(); |
189 | } | 190 | } |
190 | break; | 191 | break; |
191 | 192 | ||
192 | case BOTTOM: | 193 | case BOTTOM: |
193 | new_height = parent_rect.getHeight() - delta_y; | 194 | new_height = orig_rect.getHeight() - delta_y; |
194 | if( new_height < mMinHeight ) | 195 | if( new_height < mMinHeight ) |
195 | { | 196 | { |
196 | new_height = mMinHeight; | 197 | new_height = mMinHeight; |
197 | delta_y = parent_rect.getHeight() - mMinHeight; | 198 | delta_y = orig_rect.getHeight() - mMinHeight; |
198 | } | 199 | } |
199 | scaled_rect.translate(0, delta_y); | 200 | scaled_rect.translate(0, delta_y); |
200 | break; | 201 | break; |
@@ -202,56 +203,59 @@ BOOL LLResizeBar::handleHover(S32 x, S32 y, MASK mask) | |||
202 | 203 | ||
203 | scaled_rect.mTop = scaled_rect.mBottom + new_height; | 204 | scaled_rect.mTop = scaled_rect.mBottom + new_height; |
204 | scaled_rect.mRight = scaled_rect.mLeft + new_width; | 205 | scaled_rect.mRight = scaled_rect.mLeft + new_width; |
205 | parentView->setRect(scaled_rect); | 206 | resizing_view->setRect(scaled_rect); |
206 | |||
207 | S32 snap_delta_x = 0; | ||
208 | S32 snap_delta_y = 0; | ||
209 | 207 | ||
210 | LLView* snap_view = NULL; | 208 | LLView* snap_view = NULL; |
211 | 209 | ||
212 | switch( mSide ) | 210 | switch( mSide ) |
213 | { | 211 | { |
214 | case LEFT: | 212 | case LEFT: |
215 | snap_view = parentView->findSnapEdge(snap_delta_x, mouse_dir, SNAP_LEFT, SNAP_PARENT_AND_SIBLINGS, LLUI::sConfigGroup->getS32("SnapMargin")); | 213 | snap_view = resizing_view->findSnapEdge(scaled_rect.mLeft, 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; | 214 | break; |
219 | case TOP: | 215 | case TOP: |
220 | snap_view = parentView->findSnapEdge(snap_delta_y, mouse_dir, SNAP_TOP, SNAP_PARENT_AND_SIBLINGS, LLUI::sConfigGroup->getS32("SnapMargin")); | 216 | snap_view = resizing_view->findSnapEdge(scaled_rect.mTop, 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; | 217 | break; |
224 | case RIGHT: | 218 | case RIGHT: |
225 | snap_view = parentView->findSnapEdge(snap_delta_x, mouse_dir, SNAP_RIGHT, SNAP_PARENT_AND_SIBLINGS, LLUI::sConfigGroup->getS32("SnapMargin")); | 219 | snap_view = resizing_view->findSnapEdge(scaled_rect.mRight, 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; | 220 | break; |
229 | case BOTTOM: | 221 | case BOTTOM: |
230 | snap_view = parentView->findSnapEdge(snap_delta_y, mouse_dir, SNAP_BOTTOM, SNAP_PARENT_AND_SIBLINGS, LLUI::sConfigGroup->getS32("SnapMargin")); | 222 | snap_view = resizing_view->findSnapEdge(scaled_rect.mBottom, 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; | 223 | break; |
234 | } | 224 | } |
235 | 225 | ||
236 | parentView->snappedTo(snap_view); | 226 | // register "snap" behavior with snapped view |
227 | resizing_view->snappedTo(snap_view); | ||
237 | 228 | ||
238 | parentView->setRect(parent_rect); | 229 | // restore original rectangle so the appropriate changes are detected |
230 | resizing_view->setRect(orig_rect); | ||
231 | // change view shape as user operation | ||
232 | resizing_view->userSetShape(scaled_rect); | ||
239 | 233 | ||
240 | parentView->reshape(scaled_rect.getWidth(), scaled_rect.getHeight(), FALSE); | 234 | // update last valid mouse cursor position based on resized view's actual size |
241 | parentView->translate(scaled_rect.mLeft - parentView->getRect().mLeft, scaled_rect.mBottom - parentView->getRect().mBottom); | 235 | LLRect new_rect = resizing_view->getRect(); |
242 | 236 | switch(mSide) | |
243 | floater_view_x = mDragStartScreenX + delta_x; | 237 | { |
244 | floater_view_y = mDragStartScreenY + delta_y; | 238 | case LEFT: |
245 | mDragStartScreenX = floater_view_x + snap_delta_x; | 239 | mDragLastScreenX += new_rect.mLeft - orig_rect.mLeft; |
246 | mDragStartScreenY = floater_view_y + snap_delta_y; | 240 | break; |
241 | case RIGHT: | ||
242 | mDragLastScreenX += new_rect.mRight - orig_rect.mRight; | ||
243 | break; | ||
244 | case TOP: | ||
245 | mDragLastScreenY += new_rect.mTop - orig_rect.mTop; | ||
246 | break; | ||
247 | case BOTTOM: | ||
248 | mDragLastScreenY += new_rect.mBottom- orig_rect.mBottom; | ||
249 | break; | ||
250 | default: | ||
251 | break; | ||
252 | } | ||
247 | } | 253 | } |
248 | 254 | ||
249 | lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (active)" << llendl; | ||
250 | handled = TRUE; | 255 | handled = TRUE; |
251 | } | 256 | } |
252 | else | 257 | else |
253 | { | 258 | { |
254 | lldebugst(LLERR_USER_INPUT) << "hover handled by " << getName() << " (inactive)" << llendl; | ||
255 | handled = TRUE; | 259 | handled = TRUE; |
256 | } | 260 | } |
257 | 261 | ||