Ticket #2724: B_OUTLINE_RESIZE-1.patch
File B_OUTLINE_RESIZE-1.patch, 14.1 KB (added by , 11 years ago) |
---|
-
src/servers/app/Desktop.cpp
From a86dcb42f20d6f418104435dabf90be70c40e96c Mon Sep 17 00:00:00 2001 From: Tri-Edge AI <triedgeai@gmail.com> Date: Fri, 11 Jan 2013 21:13:33 +0200 Subject: [PATCH] Implemented BWindow flag B_OUTLINE_RESIZE --- src/servers/app/Desktop.cpp | 21 +++- src/servers/app/Desktop.h | 2 + src/servers/app/Window.cpp | 34 +++++ src/servers/app/Window.h | 2 + src/servers/app/decorator/Decorator.cpp | 15 +++ src/servers/app/decorator/Decorator.h | 4 + src/servers/app/decorator/DefaultDecorator.cpp | 133 +++++++++++++------- src/servers/app/decorator/DefaultDecorator.h | 3 + .../app/decorator/DefaultWindowBehaviour.cpp | 28 ++++- 9 files changed, 195 insertions(+), 47 deletions(-) diff --git a/src/servers/app/Desktop.cpp b/src/servers/app/Desktop.cpp index 845414a..dd08054 100644
a b Desktop::MoveWindowBy(Window* window, float x, float y, int32 workspace) 1443 1443 1444 1444 1445 1445 void 1446 Desktop::SetWindowOutlinesDelta(Window* window, BPoint delta) 1447 { 1448 AutoWriteLocker _(fWindowLock); 1449 1450 if (!window->IsVisible()) 1451 return; 1452 1453 BRegion newDirtyRegion; 1454 window->SetOutlinesDelta(delta, &newDirtyRegion); 1455 1456 BRegion background; 1457 _RebuildClippingForAllWindows(background); 1458 1459 MarkDirty(newDirtyRegion); 1460 _SetBackground(background); 1461 } 1462 1463 1464 void 1446 1465 Desktop::ResizeWindowBy(Window* window, float x, float y) 1447 1466 { 1448 1467 if (x == 0 && y == 0) … … Desktop::ResizeWindowBy(Window* window, float x, float y) 1485 1504 // make sure the window cannot mark stuff dirty outside 1486 1505 // its visible region... 1487 1506 newDirtyRegion.IntersectWith(&window->VisibleRegion()); 1488 // ...because we do this ou tself1507 // ...because we do this ourself 1489 1508 newDirtyRegion.Include(&previouslyOccupiedRegion); 1490 1509 1491 1510 MarkDirty(newDirtyRegion); -
src/servers/app/Desktop.h
diff --git a/src/servers/app/Desktop.h b/src/servers/app/Desktop.h index daa6f78..7ee0a54 100644
a b public: 172 172 173 173 void MoveWindowBy(Window* window, float x, float y, 174 174 int32 workspace = -1); 175 void SetWindowOutlinesDelta(Window* window, 176 BPoint delta); 175 177 void ResizeWindowBy(Window* window, float x, 176 178 float y); 177 179 bool SetWindowTabLocation(Window* window, -
src/servers/app/Window.cpp
diff --git a/src/servers/app/Window.cpp b/src/servers/app/Window.cpp index 117e67a..cbe8ebe 100644
a b Window::MoveBy(int32 x, int32 y, bool moveStack) 334 334 335 335 336 336 void 337 Window::SetOutlinesDelta(BPoint delta, BRegion* dirtyRegion) 338 { 339 float wantWidth = fFrame.IntegerWidth() + delta.x; 340 float wantHeight = fFrame.IntegerHeight() + delta.y; 341 342 // enforce size limits 343 WindowStack* stack = GetWindowStack(); 344 if (stack) { 345 for (int32 i = 0; i < stack->CountWindows(); i++) { 346 Window* window = stack->WindowList().ItemAt(i); 347 348 if (wantWidth < window->fMinWidth) 349 wantWidth = window->fMinWidth; 350 if (wantWidth > window->fMaxWidth) 351 wantWidth = window->fMaxWidth; 352 353 if (wantHeight < window->fMinHeight) 354 wantHeight = window->fMinHeight; 355 if (wantHeight > window->fMaxHeight) 356 wantHeight = window->fMaxHeight; 357 } 358 359 delta.x = wantWidth - fFrame.IntegerWidth(); 360 delta.y = wantHeight - fFrame.IntegerHeight(); 361 } 362 363 ::Decorator* decorator = Decorator(); 364 365 if (decorator) 366 decorator->SetOutlinesDelta(delta, dirtyRegion); 367 } 368 369 370 void 337 371 Window::ResizeBy(int32 x, int32 y, BRegion* dirtyRegion, bool resizeStack) 338 372 { 339 373 // this function is only called from the desktop thread -
src/servers/app/Window.h
diff --git a/src/servers/app/Window.h b/src/servers/app/Window.h index 6817df2..f10da63 100644
a b public: 126 126 void GetContentRegion(BRegion* region); 127 127 128 128 void MoveBy(int32 x, int32 y, bool moveStack = true); 129 void SetOutlinesDelta(BPoint delta, 130 BRegion* dirtyRegion); 129 131 void ResizeBy(int32 x, int32 y, 130 132 BRegion* dirtyRegion, 131 133 bool resizeStack = true); -
src/servers/app/decorator/Decorator.cpp
diff --git a/src/servers/app/decorator/Decorator.cpp b/src/servers/app/decorator/Decorator.cpp index 1bd90bb..afdb442 100644
a b Decorator::MoveBy(BPoint offset) 546 546 } 547 547 548 548 549 void 550 Decorator::SetOutlinesDelta(BPoint delta, BRegion* dirty) 551 { 552 _SetOutlinesDelta(delta, dirty); 553 _InvalidateFootprint(); 554 } 555 556 549 557 /*! \brief Resizes the decorator frame 550 558 551 559 This is a required function for subclasses to implement - the default does … … Decorator::_MoveBy(BPoint offset) 887 895 } 888 896 889 897 898 void 899 Decorator::_SetOutlinesDelta(BPoint offset, BRegion* dirty) 900 { 901 // Implemented by subclasses. 902 } 903 904 890 905 bool 891 906 Decorator::_SetSettings(const BMessage& settings, BRegion* updateRegion) 892 907 { -
src/servers/app/decorator/Decorator.h
diff --git a/src/servers/app/decorator/Decorator.h b/src/servers/app/decorator/Decorator.h index 40c740d..a27211e 100644
a b public: 143 143 144 144 void MoveBy(float x, float y); 145 145 void MoveBy(BPoint offset); 146 void SetOutlinesDelta(BPoint delta, BRegion* dirty); 146 147 void ResizeBy(float x, float y, BRegion* dirty); 147 148 void ResizeBy(BPoint offset, BRegion* dirty); 148 149 … … protected: 204 205 BRegion* updateRegion = NULL); 205 206 206 207 virtual void _MoveBy(BPoint offset); 208 virtual void _SetOutlinesDelta(BPoint offset, BRegion* dirty); 207 209 virtual void _ResizeBy(BPoint offset, BRegion* dirty) = 0; 208 210 209 211 virtual bool _SetSettings(const BMessage& settings, … … protected: 223 225 DrawingEngine* fDrawingEngine; 224 226 DrawState fDrawState; 225 227 228 BPoint fOutlinesDelta; 229 226 230 BRect fTitleBarRect; 227 231 BRect fFrame; 228 232 BRect fResizeRect; -
src/servers/app/decorator/DefaultDecorator.cpp
diff --git a/src/servers/app/decorator/DefaultDecorator.cpp b/src/servers/app/decorator/DefaultDecorator.cpp index 4e1b245..896367d 100644
a b DefaultDecorator::_DrawFrame(BRect invalid) 794 794 795 795 // Draw the resize knob if we're supposed to 796 796 if (!(fTopTab->flags & B_NOT_RESIZABLE)) { 797 r = fResizeRect;798 799 797 ComponentColors colors; 800 798 _GetComponentColors(COMPONENT_RESIZE_CORNER, colors, fTopTab); 801 799 802 800 switch ((int)fTopTab->look) { 803 801 case B_DOCUMENT_WINDOW_LOOK: 804 802 { 805 if (!invalid.Intersects(r)) 806 break; 807 808 float x = r.right - 3; 809 float y = r.bottom - 3; 810 811 BRect bg(x - 13, y - 13, x, y); 812 813 BGradientLinear gradient; 814 gradient.SetStart(bg.LeftTop()); 815 gradient.SetEnd(bg.RightBottom()); 816 gradient.AddColor(colors[1], 0); 817 gradient.AddColor(colors[2], 255); 818 819 fDrawingEngine->FillRect(bg, gradient); 803 if (fOutlinesDelta.x != 0 || fOutlinesDelta.y != 0) { 804 r.Set(fFrame.right - 13, fFrame.bottom - 13, 805 fFrame.right + 3, fFrame.bottom + 3); 820 806 821 fDrawingEngine->StrokeLine(BPoint(x - 15, y - 15), 822 BPoint(x - 15, y - 2), colors[0]); 823 fDrawingEngine->StrokeLine(BPoint(x - 14, y - 14), 824 BPoint(x - 14, y - 1), colors[1]); 825 fDrawingEngine->StrokeLine(BPoint(x - 15, y - 15), 826 BPoint(x - 2, y - 15), colors[0]); 827 fDrawingEngine->StrokeLine(BPoint(x - 14, y - 14), 828 BPoint(x - 1, y - 14), colors[1]); 807 if (invalid.Intersects(r)) 808 _DrawResizeKnob(r, false, colors); 809 } 829 810 830 if ( fTopTab && !IsFocus(fTopTab))831 break;811 if (invalid.Intersects(fResizeRect)) 812 _DrawResizeKnob(fResizeRect, fTopTab && IsFocus(fTopTab), colors); 832 813 833 static const rgb_color kWhite834 = (rgb_color){ 255, 255, 255, 255 };835 for (int8 i = 1; i <= 4; i++) {836 for (int8 j = 1; j <= i; j++) {837 BPoint pt1(x - (3 * j) + 1, y - (3 * (5 - i)) + 1);838 BPoint pt2(x - (3 * j) + 2, y - (3 * (5 - i)) + 2);839 fDrawingEngine->StrokePoint(pt1, colors[0]);840 fDrawingEngine->StrokePoint(pt2, kWhite);841 }842 }843 814 break; 844 815 } 845 816 … … DefaultDecorator::_DrawFrame(BRect invalid) 873 844 874 845 875 846 void 847 DefaultDecorator::_DrawResizeKnob(BRect r, bool full, const ComponentColors& colors) 848 { 849 float x = r.right -= 3; 850 float y = r.bottom -= 3; 851 852 BGradientLinear gradient; 853 gradient.SetStart(r.LeftTop()); 854 gradient.SetEnd(r.RightBottom()); 855 gradient.AddColor(colors[1], 0); 856 gradient.AddColor(colors[2], 255); 857 858 fDrawingEngine->FillRect(r, gradient); 859 860 fDrawingEngine->StrokeLine(BPoint(x - 15, y - 15), 861 BPoint(x - 15, y - 2), colors[0]); 862 fDrawingEngine->StrokeLine(BPoint(x - 14, y - 14), 863 BPoint(x - 14, y - 1), colors[1]); 864 fDrawingEngine->StrokeLine(BPoint(x - 15, y - 15), 865 BPoint(x - 2, y - 15), colors[0]); 866 fDrawingEngine->StrokeLine(BPoint(x - 14, y - 14), 867 BPoint(x - 1, y - 14), colors[1]); 868 869 if (!full) 870 return; 871 872 static const rgb_color kWhite 873 = (rgb_color){ 255, 255, 255, 255 }; 874 for (int8 i = 1; i <= 4; i++) { 875 for (int8 j = 1; j <= i; j++) { 876 BPoint pt1(x - (3 * j) + 1, y - (3 * (5 - i)) + 1); 877 BPoint pt2(x - (3 * j) + 2, y - (3 * (5 - i)) + 2); 878 fDrawingEngine->StrokePoint(pt1, colors[0]); 879 fDrawingEngine->StrokePoint(pt2, kWhite); 880 } 881 } 882 } 883 884 885 void 876 886 DefaultDecorator::_DrawTab(Decorator::Tab* tab, BRect invalid) 877 887 { 878 888 STRACE(("_DrawTab(%.1f,%.1f,%.1f,%.1f)\n", … … DefaultDecorator::_MoveBy(BPoint offset) 1151 1161 1152 1162 1153 1163 void 1164 DefaultDecorator::_SetOutlinesDelta(BPoint delta, BRegion* dirty) 1165 { 1166 BPoint offset = delta - fOutlinesDelta; 1167 fOutlinesDelta = delta; 1168 1169 dirty->Include(fLeftBorder); 1170 dirty->Include(fRightBorder); 1171 dirty->Include(fTopBorder); 1172 dirty->Include(fBottomBorder); 1173 1174 fBorderRect.right += offset.x; 1175 fBorderRect.bottom += offset.y; 1176 1177 fLeftBorder.bottom += offset.y; 1178 fTopBorder.right += offset.x; 1179 1180 fRightBorder.OffsetBy(offset.x, 0.0); 1181 fRightBorder.bottom += offset.y; 1182 1183 fBottomBorder.OffsetBy(0.0, offset.y); 1184 fBottomBorder.right += offset.x; 1185 1186 dirty->Include(fLeftBorder); 1187 dirty->Include(fRightBorder); 1188 dirty->Include(fTopBorder); 1189 dirty->Include(fBottomBorder); 1190 1191 dirty->Exclude(fFrame); 1192 // The key thing about B_OUTLINE_RESIZE 1193 1194 dirty->Include(fResizeRect); 1195 fResizeRect.OffsetBy(offset); 1196 dirty->Include(fResizeRect); 1197 } 1198 1199 1200 void 1154 1201 DefaultDecorator::_ResizeBy(BPoint offset, BRegion* dirty) 1155 1202 { 1156 1203 STRACE(("DefaultDecorator: Resize By (%.1f, %.1f)\n", offset.x, offset.y)); … … DefaultDecorator::_SetTabLocation(Decorator::Tab* _tab, float location, 1315 1362 fOldMovingTab = _tab->tabRect; 1316 1363 } 1317 1364 } 1318 1365 1319 1366 DefaultDecorator::Tab* tab = static_cast<DefaultDecorator::Tab*>(_tab); 1320 1367 BRect& tabRect = tab->tabRect; 1321 1368 if (tabRect.IsValid() == false) … … DefaultDecorator::_SetTabLocation(Decorator::Tab* _tab, float location, 1357 1404 rect.bottom++; 1358 1405 if (updateRegion != NULL) 1359 1406 updateRegion->Include(rect); 1360 1407 1361 1408 return true; 1362 1409 } 1363 1410 … … DefaultDecorator::_GetFootprint(BRegion *region) 1455 1502 region->Include(&fTabsRegion); 1456 1503 1457 1504 if (fTopTab->look == B_DOCUMENT_WINDOW_LOOK) { 1458 // include the rectangular resize knob on the bottom right1459 float knobSize = kResizeKnobSize - fBorderWidth;1460 region->Include(BRect(fFrame.right - knobSize, fFrame.bottom - knobSize, 1461 fFrame.right, fFrame.bottom));1505 region->Include(BRect(fFrame.right - 13.0f, fFrame.bottom - 13.0f, 1506 fFrame.right, fFrame.bottom)); 1507 1508 region->Include(fResizeRect); 1462 1509 } 1463 1510 } 1464 1511 -
src/servers/app/decorator/DefaultDecorator.h
diff --git a/src/servers/app/decorator/DefaultDecorator.h b/src/servers/app/decorator/DefaultDecorator.h index 7f46309..ca3a67c 100644
a b protected: 110 110 DefaultDecorator::Tab* _TabAt(int32 index) const; 111 111 112 112 virtual void _DrawFrame(BRect r); 113 virtual void _DrawResizeKnob(BRect r, bool full, 114 const ComponentColors& color); 113 115 virtual void _DrawTab(Decorator::Tab* tab, BRect r); 114 116 115 117 virtual void _DrawClose(Decorator::Tab* tab, bool direct, … … protected: 132 134 BRegion* updateRegion = NULL); 133 135 134 136 virtual void _MoveBy(BPoint offset); 137 virtual void _SetOutlinesDelta(BPoint delta, BRegion* dirty); 135 138 virtual void _ResizeBy(BPoint offset, BRegion* dirty); 136 139 137 140 virtual bool _SetTabLocation(Decorator::Tab* tab, -
src/servers/app/decorator/DefaultWindowBehaviour.cpp
diff --git a/src/servers/app/decorator/DefaultWindowBehaviour.cpp b/src/servers/app/decorator/DefaultWindowBehaviour.cpp index d6650d0..5681a96 100644
a b 17 17 18 18 #include <math.h> 19 19 20 #include <PortLink.h> 20 21 #include <WindowPrivate.h> 21 22 23 #include "AppServer.h" 22 24 #include "ClickTarget.h" 23 25 #include "Desktop.h" 24 26 #include "DefaultDecorator.h" … … struct DefaultWindowBehaviour::DragState : MouseTrackingState { 250 252 251 253 252 254 struct DefaultWindowBehaviour::ResizeState : MouseTrackingState { 255 BPoint fDelta; 256 253 257 ResizeState(DefaultWindowBehaviour& behavior, BPoint where, 254 258 bool activateOnMouseUp) 255 259 : 256 MouseTrackingState(behavior, where, activateOnMouseUp, false) 260 MouseTrackingState(behavior, where, activateOnMouseUp, true) 261 { 262 fDelta = BPoint(0, 0); 263 } 264 265 virtual void EnterState(State* prevState) 266 { 267 268 } 269 270 virtual void ExitState(State* nextState) 257 271 { 272 if (fWindow->Flags() & B_OUTLINE_RESIZE) { 273 fDesktop->SetWindowOutlinesDelta(fWindow, BPoint(0, 0)); 274 fDesktop->ResizeWindowBy(fWindow, fDelta.x, fDelta.y); 275 } 258 276 } 259 277 260 278 virtual void MouseMovedAction(BPoint& delta, bigtime_t now) … … struct DefaultWindowBehaviour::ResizeState : MouseTrackingState { 267 285 268 286 BPoint oldRightBottom = fWindow->Frame().RightBottom(); 269 287 270 fDesktop->ResizeWindowBy(fWindow, delta.x, delta.y); 288 if (fWindow->Flags() & B_OUTLINE_RESIZE) { 289 fDelta = delta; 290 fDesktop->SetWindowOutlinesDelta(fWindow, delta); 291 } else 292 fDesktop->ResizeWindowBy(fWindow, delta.x, delta.y); 271 293 272 294 // constrain delta to true change in size 273 295 delta = fWindow->Frame().RightBottom() - oldRightBottom; … … struct DefaultWindowBehaviour::SlideTabState : MouseTrackingState { 336 358 neighbourTab->tabOffset + neighbourTab->tabRect.Width() / 2) 337 359 return; 338 360 } 339 361 340 362 fWindow->MoveToStackPosition(neighbourIndex, isShifting); 341 363 } 342 364 };