From df9bb1df9717c8e30b626951b809a357a7177177 Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Tue, 7 Sep 2010 12:14:20 +0000 Subject: [PATCH] Reworked, as suggested by stippi, to avoid keeping cursors instances of system ones. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38566 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/glteapot/ObjectView.cpp | 16 ++++++------ src/apps/glteapot/ObjectView.h | 3 --- .../backgrounds/BackgroundsView.cpp | 25 ++++++++----------- src/preferences/backgrounds/BackgroundsView.h | 3 --- 4 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/apps/glteapot/ObjectView.cpp b/src/apps/glteapot/ObjectView.cpp index b58eb01d52..85cfbc9710 100644 --- a/src/apps/glteapot/ObjectView.cpp +++ b/src/apps/glteapot/ObjectView.cpp @@ -166,9 +166,6 @@ ObjectView::ObjectView(BRect rect, const char *name, ulong resizingMode, quittingSem = create_sem(1, "quitting sem"); drawEvent = create_sem(0, "draw event"); - fGrabbingCursor = new BCursor(B_CURSOR_ID_GRABBING); - fGrabCursor = new BCursor(B_CURSOR_ID_GRAB); - char findDir[PATH_MAX]; find_directory(B_SYSTEM_DATA_DIRECTORY, -1, true, findDir, PATH_MAX); sprintf(teapotPath, "%s/%s", findDir, teapotData); @@ -182,8 +179,6 @@ ObjectView::~ObjectView() { delete_sem(quittingSem); delete_sem(drawEvent); - delete fGrabCursor; - delete fGrabbingCursor; } @@ -439,7 +434,9 @@ ObjectView::MouseDown(BPoint point) SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); - SetViewCursor(fGrabbingCursor); + + BCursor grabbingCursor(B_CURSOR_ID_GRABBING); + SetViewCursor(&grabbingCursor); } else { ConvertToScreen(&point); object->MenuInvoked(point); @@ -473,7 +470,8 @@ ObjectView::MouseUp(BPoint point) fTrackingInfo.lastDx = 0.0f; fTrackingInfo.lastDy = 0.0f; - SetViewCursor(fGrabCursor); + BCursor grabCursor(B_CURSOR_ID_GRAB); + SetViewCursor(&grabCursor); } } @@ -520,7 +518,9 @@ ObjectView::MouseMoved(BPoint point, uint32 transit, const BMessage *msg) } } else { GLObject* object = reinterpret_cast(fObjects.ItemAt(ObjectAtPoint(point))); - SetViewCursor(object != NULL ? fGrabCursor : B_CURSOR_SYSTEM_DEFAULT); + BCursor cursor(object != NULL ? + B_CURSOR_ID_GRAB : B_CURSOR_ID_SYSTEM_DEFAULT); + SetViewCursor(&cursor); } } diff --git a/src/apps/glteapot/ObjectView.h b/src/apps/glteapot/ObjectView.h index b44246798f..fc7b59a643 100644 --- a/src/apps/glteapot/ObjectView.h +++ b/src/apps/glteapot/ObjectView.h @@ -40,7 +40,6 @@ enum lights { class ResScroll; class GLObject; -class BCursor; struct TrackingInfo { float lastX; @@ -91,8 +90,6 @@ class ObjectView : public BGLView { float fLastYXRatio, fYxRatio, fFpsHistory[HISTSIZE]; float fObjectDistance, fLastObjectDistance; TrackingInfo fTrackingInfo; - BCursor* fGrabCursor; - BCursor* fGrabbingCursor; }; #endif // OBJECT_VIEW_H diff --git a/src/preferences/backgrounds/BackgroundsView.cpp b/src/preferences/backgrounds/BackgroundsView.cpp index f7c09876dc..f0def5719c 100644 --- a/src/preferences/backgrounds/BackgroundsView.cpp +++ b/src/preferences/backgrounds/BackgroundsView.cpp @@ -1146,9 +1146,7 @@ BackgroundsView::FoundPositionSetting() PreView::PreView() : - BControl("PreView", NULL, NULL, B_WILL_DRAW | B_SUBPIXEL_PRECISE), - fGrabbingCursor(new BCursor(B_CURSOR_ID_GRABBING)), - fGrabCursor(new BCursor(B_CURSOR_ID_GRAB)) + BControl("PreView", NULL, NULL, B_WILL_DRAW | B_SUBPIXEL_PRECISE) { float aspectRatio = BScreen().Frame().Width() / BScreen().Frame().Height(); float previewWidth = 120.0f; @@ -1160,13 +1158,6 @@ PreView::PreView() } -PreView::~PreView() -{ - delete fGrabbingCursor; - delete fGrabCursor; -} - - void PreView::AttachedToWindow() { @@ -1190,7 +1181,9 @@ PreView::MouseDown(BPoint point) fYRatio = Bounds().Height() / fMode.virtual_height; SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); - SetViewCursor(fGrabbingCursor); + + BCursor grabbingCursor(B_CURSOR_ID_GRABBING); + SetViewCursor(&grabbingCursor); } } } @@ -1201,7 +1194,8 @@ PreView::MouseUp(BPoint point) { if (IsTracking()) { SetTracking(false); - SetViewCursor(fGrabCursor); + BCursor grabCursor(B_CURSOR_ID_GRAB); + SetViewCursor(&grabCursor); } } @@ -1209,9 +1203,10 @@ PreView::MouseUp(BPoint point) void PreView::MouseMoved(BPoint point, uint32 transit, const BMessage* message) { - if (!IsTracking()) - SetViewCursor(IsEnabled() ? fGrabCursor : B_CURSOR_SYSTEM_DEFAULT); - else { + if (!IsTracking()) { + BCursor cursor(IsEnabled() ? B_CURSOR_ID_GRAB : B_CURSOR_ID_SYSTEM_DEFAULT); + SetViewCursor(&cursor); + } else { float x, y; x = fPoint.x + (point.x - fOldPoint.x) / fXRatio; y = fPoint.y + (point.y - fOldPoint.y) / fYRatio; diff --git a/src/preferences/backgrounds/BackgroundsView.h b/src/preferences/backgrounds/BackgroundsView.h index ca13def6f8..692065c247 100644 --- a/src/preferences/backgrounds/BackgroundsView.h +++ b/src/preferences/backgrounds/BackgroundsView.h @@ -81,7 +81,6 @@ private: class PreView : public BControl { public: PreView(); - virtual ~PreView(); BPoint fPoint; BRect fImageBounds; @@ -97,8 +96,6 @@ protected: float fXRatio; float fYRatio; display_mode fMode; - BCursor* fGrabbingCursor; - BCursor* fGrabCursor; };