added scrolling with the right mouse button

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12728 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2005-05-18 23:42:58 +00:00
parent 62f9753de5
commit 1fd87770e9
3 changed files with 44 additions and 21 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ if ( $(TARGET_PLATFORM) = haiku ) {
} else { } else {
# for running in the Haiku app_server under R5: # for running in the Haiku app_server under R5:
LinkSharedOSLibs Playground : LinkSharedOSLibs Playground :
<boot!home!config!lib>libopenbeos.so ; # <boot!home!config!lib>libopenbeos.so ;
# be ; be ;
} }
@@ -18,7 +18,9 @@ ObjectView::ObjectView(BRect frame, const char* name,
fStateList(20), fStateList(20),
fColor((rgb_color){ 0, 80, 255, 100 }), fColor((rgb_color){ 0, 80, 255, 100 }),
fFill(false), fFill(false),
fPenSize(10.0) fPenSize(10.0),
fScrolling(false),
fLastMousePos(0.0, 0.0)
{ {
rgb_color bg = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_1_TINT); rgb_color bg = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_LIGHTEN_1_TINT);
SetViewColor(bg); SetViewColor(bg);
@@ -41,7 +43,7 @@ ObjectView::Draw(BRect updateRect)
BRect r(Bounds()); BRect r(Bounds());
BeginLineArray(4); /* BeginLineArray(4);
AddLine(BPoint(r.left, r.top), AddLine(BPoint(r.left, r.top),
BPoint(r.right, r.top), shadow); BPoint(r.right, r.top), shadow);
AddLine(BPoint(r.right, r.top + 1), AddLine(BPoint(r.right, r.top + 1),
@@ -50,7 +52,7 @@ ObjectView::Draw(BRect updateRect)
BPoint(r.left, r.bottom), light); BPoint(r.left, r.bottom), light);
AddLine(BPoint(r.left, r.bottom - 1), AddLine(BPoint(r.left, r.bottom - 1),
BPoint(r.left, r.top + 1), shadow); BPoint(r.left, r.top + 1), shadow);
EndLineArray(); EndLineArray();*/
SetHighColor(255, 0, 0, 128); SetHighColor(255, 0, 0, 128);
@@ -82,6 +84,13 @@ SetDrawingMode(B_OP_COPY);
void void
ObjectView::MouseDown(BPoint where) ObjectView::MouseDown(BPoint where)
{ {
uint32 buttons;
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
fScrolling = buttons & B_SECONDARY_MOUSE_BUTTON;
if (fScrolling) {
fLastMousePos = where;
} else {
if (!fState) if (!fState)
SetState(State::StateFor(fObjectType, fColor, fFill, fPenSize)); SetState(State::StateFor(fObjectType, fColor, fFill, fPenSize));
@@ -90,15 +99,20 @@ ObjectView::MouseDown(BPoint where)
fState->MouseDown(where); fState->MouseDown(where);
Invalidate(fState->Bounds()); Invalidate(fState->Bounds());
} }
}
} }
// MouseUp // MouseUp
void void
ObjectView::MouseUp(BPoint where) ObjectView::MouseUp(BPoint where)
{ {
if (fScrolling) {
fScrolling = false;
} else {
if (fState) { if (fState) {
fState->MouseUp(where); fState->MouseUp(where);
} }
}
} }
// MouseMoved // MouseMoved
@@ -106,6 +120,11 @@ void
ObjectView::MouseMoved(BPoint where, uint32 transit, ObjectView::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage) const BMessage* dragMessage)
{ {
if (fScrolling) {
BPoint offset = fLastMousePos - where;
ScrollBy(offset.x, offset.y);
fLastMousePos = where + offset;
} else {
if (fState && fState->IsTracking()) { if (fState && fState->IsTracking()) {
BRect before = fState->Bounds(); BRect before = fState->Bounds();
@@ -115,6 +134,7 @@ ObjectView::MouseMoved(BPoint where, uint32 transit,
BRect invalid(before | after); BRect invalid(before | after);
Invalidate(invalid); Invalidate(invalid);
} }
}
} }
// SetState // SetState
@@ -59,6 +59,9 @@ class ObjectView : public BView {
rgb_color fColor; rgb_color fColor;
bool fFill; bool fFill;
float fPenSize; float fPenSize;
bool fScrolling;
BPoint fLastMousePos;
}; };
#endif // OBJECT_VIEW_H #endif // OBJECT_VIEW_H