From a332730df786a7aa05833ed53fd351eebabe88ba Mon Sep 17 00:00:00 2001 From: Adi Oanca Date: Sun, 29 May 2005 16:11:16 +0000 Subject: [PATCH] - moving and resizing is new performed only with the primary mouse button - by holding the secondary mouse button pressed one can draw random lines so you can see what regions are invalidated durring a move, resize or scroll operation - clicking the third mouse button issues a redraw, WITHOUT a region rebuild action (this is to force a redraw because the window does not redraw itself, I've been lazy :-) - playing with the mouse wheel results in the layer under mouse cursor being scrolled on the y-axis. - fixed redraw and copyRegion of this sandbox app. They work correctly now. - TODO: fix a clipping bug which appears when moving a layer arround. --This line, and those below, will be ignored-- M newClipping/MyView.cpp M newClipping/main.cpp M newClipping/MyView.h M newClipping/Layer.cpp M newClipping/Clipping.proj git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12895 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../servers/app/newClipping/Clipping.proj | Bin 12308 -> 12308 bytes src/tests/servers/app/newClipping/Layer.cpp | 9 +- src/tests/servers/app/newClipping/MyView.cpp | 84 +++++++++++++++--- src/tests/servers/app/newClipping/MyView.h | 2 + src/tests/servers/app/newClipping/main.cpp | 9 +- 5 files changed, 82 insertions(+), 22 deletions(-) diff --git a/src/tests/servers/app/newClipping/Clipping.proj b/src/tests/servers/app/newClipping/Clipping.proj index e9bbc983274eb641e1e0d602f927317be45dad10..1ebb697a9bea53d77f58cb73026a3228c8612697 100644 GIT binary patch delta 129 zcmbP|FePEb0XCKk{W1-c7w|f6W@Z1W!W=VMWiz9W5Tj@V0|NsK5HkZYLjw>y%__Py z`LC|pWIx?mqIW@}K)?hd8i3eoR&Fj(b~Q7ER-1fLZ=M*pKS&w~kdzgIl&MW#t)B@1 DCBP#L delta 129 zcmbP|FePEb0XCKob7UGOFW`0D%*y^#h55}-watt=LX4sb3=9k`K+Fup3=Kf+G&AV< zCurrentMessage()->FindInt32("buttons", &buttons); fLastPos = where; - fMovingLayer = FindLayer(topLayer, where); - if (fMovingLayer == topLayer) - fMovingLayer = NULL; - if (fMovingLayer) + if (buttons == B_PRIMARY_MOUSE_BUTTON) { - BRect bounds(fMovingLayer->Bounds()); - fMovingLayer->ConvertToScreen2(&bounds); - BRect resizeRect(bounds.right-10, bounds.bottom-10, bounds.right, bounds.bottom); - if (resizeRect.Contains(where)) - fIsResize = true; - else - fIsResize = false; + fTracking = true; + fMovingLayer = FindLayer(topLayer, where); + if (fMovingLayer == topLayer) + fMovingLayer = NULL; + if (fMovingLayer) + { + BRect bounds(fMovingLayer->Bounds()); + fMovingLayer->ConvertToScreen2(&bounds); + BRect resizeRect(bounds.right-10, bounds.bottom-10, bounds.right, bounds.bottom); + if (resizeRect.Contains(where)) + fIsResize = true; + else + fIsResize = false; + } + } + else if (buttons == B_SECONDARY_MOUSE_BUTTON) + { + fIs2ndButton = true; + } + else if (buttons == B_TERTIARY_MOUSE_BUTTON) + { + DrawSubTree(topLayer); } } void MyView::MouseUp(BPoint where) { fTracking = false; + fIs2ndButton = false; fMovingLayer = NULL; } @@ -93,27 +108,67 @@ void MyView::MouseMoved(BPoint where, uint32 code, const BMessage *a_message) } } } + else if (fIs2ndButton) + { + SetHighColor(0,0,0); + StrokeLine(fLastPos, where); + Flush(); + fLastPos = where; + } +} + +void MyView::MessageReceived(BMessage *msg) +{ + switch(msg->what) + { + case B_MOUSE_WHEEL_CHANGED: + { + float dy; + msg->FindFloat("be:wheel_delta_y", &dy); + + BPoint pt; + uint32 buttons; + Layer *lay; + GetMouse(&pt, &buttons, false); + if ((lay = FindLayer(topLayer, pt))) + lay->ScrollBy(0, dy*5); + break; + } + default: + BView::MessageReceived(msg); + } } void MyView::CopyRegion(BRegion *reg, float dx, float dy) { // Yes... in this sandbox app, do a redraw. + reg->OffsetBy(dx, dy); wind->Lock(); ConstrainClippingRegion(reg); + PushState(); DrawSubTree(topLayer); - Flush(); + PopState(); + ConstrainClippingRegion(NULL); wind->Unlock(); } void MyView::RequestRedraw() { wind->Lock(); - Invalidate(); + ConstrainClippingRegion(&fRedrawReg); + PushState(); + DrawSubTree(topLayer); + PopState(); + ConstrainClippingRegion(NULL); + + fRedrawReg.MakeEmpty(); + wind->Unlock(); } void MyView::Draw(BRect area) { +/* ConstrainClippingRegion(&fRedrawReg); //FillRect(Bounds()); //Flush(); @@ -123,6 +178,7 @@ void MyView::Draw(BRect area) PopState(); ConstrainClippingRegion(NULL); fRedrawReg.MakeEmpty(); +*/ } void MyView::DrawSubTree(Layer* lay) diff --git a/src/tests/servers/app/newClipping/MyView.h b/src/tests/servers/app/newClipping/MyView.h index 637d192200..ce2e53bd93 100644 --- a/src/tests/servers/app/newClipping/MyView.h +++ b/src/tests/servers/app/newClipping/MyView.h @@ -14,6 +14,7 @@ public: virtual void MouseDown(BPoint where); virtual void MouseUp(BPoint where); virtual void MouseMoved(BPoint where, uint32 code, const BMessage *a_message); + virtual void MessageReceived(BMessage*); void CopyRegion(BRegion *reg, float dx, float dy); void RequestRedraw(); @@ -29,4 +30,5 @@ private: BPoint fLastPos; Layer *fMovingLayer; bool fIsResize; + bool fIs2ndButton; }; \ No newline at end of file diff --git a/src/tests/servers/app/newClipping/main.cpp b/src/tests/servers/app/newClipping/main.cpp index 1bbfa63372..ed2852a9c5 100644 --- a/src/tests/servers/app/newClipping/main.cpp +++ b/src/tests/servers/app/newClipping/main.cpp @@ -66,6 +66,7 @@ clsMainWindow::clsMainWindow(const char *uWindowTitle) wind = this; fView = new MyView(Bounds(), "emu", B_FOLLOW_ALL, B_WILL_DRAW); AddChild(fView); + fView->MakeFocus(true); } clsMainWindow::~clsMainWindow() @@ -157,15 +158,13 @@ void clsMainWindow::test1() wb2->GetWantedRegion(temp); topLayer->RebuildVisibleRegions(temp, wb2); - wind->Lock(); - fView->Invalidate(); - wind->Unlock(); + fView->RequestRedraw(); - snooze(2000000); + snooze(1000000); wb1->Hide(); - snooze(2000000); + snooze(1000000); wb1->Show();