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

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 ;
} }

View File

@ -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,13 +84,21 @@ SetDrawingMode(B_OP_COPY);
void void
ObjectView::MouseDown(BPoint where) ObjectView::MouseDown(BPoint where)
{ {
if (!fState) uint32 buttons;
SetState(State::StateFor(fObjectType, fColor, fFill, fPenSize)); Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
fScrolling = buttons & B_SECONDARY_MOUSE_BUTTON;
if (fState) { if (fScrolling) {
Invalidate(fState->Bounds()); fLastMousePos = where;
fState->MouseDown(where); } else {
Invalidate(fState->Bounds()); if (!fState)
SetState(State::StateFor(fObjectType, fColor, fFill, fPenSize));
if (fState) {
Invalidate(fState->Bounds());
fState->MouseDown(where);
Invalidate(fState->Bounds());
}
} }
} }
@ -96,8 +106,12 @@ ObjectView::MouseDown(BPoint where)
void void
ObjectView::MouseUp(BPoint where) ObjectView::MouseUp(BPoint where)
{ {
if (fState) { if (fScrolling) {
fState->MouseUp(where); fScrolling = false;
} else {
if (fState) {
fState->MouseUp(where);
}
} }
} }
@ -106,14 +120,20 @@ void
ObjectView::MouseMoved(BPoint where, uint32 transit, ObjectView::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage) const BMessage* dragMessage)
{ {
if (fState && fState->IsTracking()) { if (fScrolling) {
BRect before = fState->Bounds(); BPoint offset = fLastMousePos - where;
ScrollBy(offset.x, offset.y);
fLastMousePos = where + offset;
} else {
if (fState && fState->IsTracking()) {
BRect before = fState->Bounds();
fState->MouseMoved(where); fState->MouseMoved(where);
BRect after = fState->Bounds(); BRect after = fState->Bounds();
BRect invalid(before | after); BRect invalid(before | after);
Invalidate(invalid); Invalidate(invalid);
}
} }
} }

View File

@ -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