From 269293b0ea85fbc2187e43ccdc6e6db77c410309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 5 Jan 2006 23:51:23 +0000 Subject: [PATCH] Selected objects can be removed with the delete key. Added testbed for BTabView. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15847 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../servers/app/playground/ObjectView.cpp | 71 +++++++++++++++++-- src/tests/servers/app/playground/ObjectView.h | 1 + .../servers/app/playground/ObjectWindow.cpp | 52 ++++++++++++-- src/tests/servers/app/playground/States.cpp | 2 +- src/tests/servers/app/playground/States.h | 2 +- 5 files changed, 115 insertions(+), 13 deletions(-) diff --git a/src/tests/servers/app/playground/ObjectView.cpp b/src/tests/servers/app/playground/ObjectView.cpp index 7952c2c55d..13cd609b37 100644 --- a/src/tests/servers/app/playground/ObjectView.cpp +++ b/src/tests/servers/app/playground/ObjectView.cpp @@ -37,6 +37,16 @@ ObjectView::ObjectView(BRect frame, const char* name, // font.SetSize(20.0); //// font.SetRotation(6.0); // SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_ROTATION | B_FONT_SIZE); + +// State* state = State::StateFor(OBJECT_ROUND_RECT, fColor, B_OP_COPY, +// false, 50.0); +// state->MouseDown(BPoint(15, 15)); +// state->MouseMoved(BPoint(255, 305)); +// state->MouseUp(); +// +// AddObject(state); + + SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); } // AttachedToWindow @@ -77,16 +87,48 @@ ObjectView::Draw(BRect updateRect) BPoint p(r.Width() / 2.0 - width / 2.0, r.Height() / 2.0); -Sync(); -bigtime_t now = system_time(); +//Sync(); +//bigtime_t now = system_time(); DrawString(message, p); -Sync(); -printf("Drawing Text: %lld\n", system_time() - now); +//Sync(); +//printf("Drawing Text: %lld\n", system_time() - now); + +// r.OffsetTo(B_ORIGIN); +// +//now = system_time(); +// int32 rectCount = 20; +// BeginLineArray(4 * rectCount); +// for (int32 i = 0; i < rectCount; i++) { +// r.InsetBy(5, 5); +// +// AddLine(BPoint(r.left, r.top), +// BPoint(r.right, r.top), shadow); +// AddLine(BPoint(r.right, r.top + 1), +// BPoint(r.right, r.bottom), light); +// AddLine(BPoint(r.right - 1, r.bottom), +// BPoint(r.left, r.bottom), light); +// AddLine(BPoint(r.left, r.bottom - 1), +// BPoint(r.left, r.top + 1), shadow); +// } +// EndLineArray(); +//Sync(); +//printf("Drawing Lines: %lld\n", system_time() - now); + +//Flush(); +//Sync(); +//bigtime_t start = system_time(); +//SetDrawingMode(B_OP_ALPHA); +//SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY); +//SetHighColor(0, 0, 255, 128); +//FillRect(BRect(0, 0, 250, 300)); +//Sync(); +//printf("Alpha Fill: %lld\n", system_time() - start); for (int32 i = 0; State* state = (State*)fStateList.ItemAt(i); i++) state->Draw(this); - +//Sync(); +//printf("State: %lld\n", system_time() - start); } // MouseDown @@ -126,7 +168,7 @@ ObjectView::MouseUp(BPoint where) fScrolling = false; } else { if (fState) { - fState->MouseUp(where); + fState->MouseUp(); } } } @@ -136,7 +178,6 @@ void ObjectView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage) { - if (dragMessage) { //printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f)) - DRAG MESSAGE\n", where.x, where.y); //Window()->CurrentMessage()->PrintToStream(); @@ -229,6 +270,22 @@ ObjectView::AddObject(State* state) } } +// RemoveObject +void +ObjectView::RemoveObject(State* state) +{ + if (state && fStateList.RemoveItem((void*)state)) { + if (fState == state) + SetState(NULL); + else + Invalidate(state->Bounds()); + + Window()->PostMessage(MSG_OBJECT_COUNT_CHANGED); + + delete state; + } +} + // CountObjects int32 ObjectView::CountObjects() const diff --git a/src/tests/servers/app/playground/ObjectView.h b/src/tests/servers/app/playground/ObjectView.h index cb30e54607..a9e656ecdf 100644 --- a/src/tests/servers/app/playground/ObjectView.h +++ b/src/tests/servers/app/playground/ObjectView.h @@ -38,6 +38,7 @@ class ObjectView : public BView { { return fObjectType; } void AddObject(State* state); + void RemoveObject(State* state); int32 CountObjects() const; void MakeEmpty(); diff --git a/src/tests/servers/app/playground/ObjectWindow.cpp b/src/tests/servers/app/playground/ObjectWindow.cpp index 53c7c8481f..cf3d8d81c6 100644 --- a/src/tests/servers/app/playground/ObjectWindow.cpp +++ b/src/tests/servers/app/playground/ObjectWindow.cpp @@ -45,6 +45,7 @@ enum { MSG_CLEAR = 'clir', MSG_OBJECT_SELECTED = 'obsl', + MSG_REMOVE_OBJECT = 'rmob', }; // ObjectItem @@ -63,6 +64,26 @@ class ObjectItem : public BStringItem { State* fObject; }; +// ObjectListView +class ObjectListView : public BListView { + public: + ObjectListView(BRect frame, const char* name, list_view_type listType) + : BListView(frame, name, listType) + { + } + + virtual void KeyDown(const char* bytes, int32 numBytes) + { + switch (*bytes) { + case B_DELETE: + Window()->PostMessage(MSG_REMOVE_OBJECT); + break; + default: + BListView::KeyDown(bytes, numBytes); + } + } +}; + // #pragma mark - // constructor @@ -297,10 +318,10 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name) b.top += 10.0; b.InsetBy(9.0, 7.0); b.left = b.left + b.Width() / 2.0 + 6.0; - b.right = b.right - B_V_SCROLL_BAR_WIDTH; + b.right -= B_V_SCROLL_BAR_WIDTH; b.bottom = fDrawingModeMF->Frame().top - 5.0; - fObjectLV = new BListView(b, "object list", B_MULTIPLE_SELECTION_LIST); + fObjectLV = new ObjectListView(b, "object list", B_MULTIPLE_SELECTION_LIST); fObjectLV->SetSelectionMessage(new BMessage(MSG_OBJECT_SELECTED)); // wrap a scroll view around the list view @@ -309,6 +330,20 @@ b.bottom = fDrawingModeMF->Frame().top - 5.0; B_FANCY_BORDER); controlGroup->AddChild(scrollView); + // add a dummy tab view + b.top = b.bottom + 10.0; + b.right += B_V_SCROLL_BAR_WIDTH; + b.bottom = controlGroup->Bounds().bottom - 7.0; + BTabView* tabView = new BTabView(b, "tab view", B_WIDTH_FROM_WIDEST, + B_FOLLOW_ALL, B_FULL_UPDATE_ON_RESIZE | + B_WILL_DRAW | B_NAVIGABLE_JUMP | + B_FRAME_EVENTS | B_NAVIGABLE); + + tabView->AddTab(new BView(BRect(0, 0, 40, 40), "T", B_FOLLOW_ALL, 0)); + tabView->AddTab(new BView(BRect(0, 0, 40, 40), "T", B_FOLLOW_ALL, 0)); + tabView->AddTab(new BView(BRect(0, 0, 40, 40), "T", B_FOLLOW_ALL, 0)); + controlGroup->AddChild(tabView); + // enforce some size limits float minWidth = controlGroup->Frame().Width() + 30.0; float minHeight = fPenSizeS->Frame().bottom + @@ -375,19 +410,28 @@ ObjectWindow::MessageReceived(BMessage* message) fClearB->SetEnabled(fObjectView->CountObjects() > 0); break; case MSG_OBJECT_SELECTED: -printf("MSG_OBJECT_SELECTED\n"); if (ObjectItem* item = (ObjectItem*)fObjectLV->ItemAt(fObjectLV->CurrentSelection(0))) { fObjectView->SetState(item->Object()); } else fObjectView->SetState(NULL); break; + case MSG_REMOVE_OBJECT: + while (ObjectItem* item = (ObjectItem*)fObjectLV->ItemAt(fObjectLV->CurrentSelection(0))) { + fObjectView->RemoveObject(item->Object()); + fObjectLV->RemoveItem(item); + delete item; + } + break; case MSG_NEW_OBJECT: fObjectView->SetState(NULL); break; case MSG_CLEAR: { - BAlert *alert = new BAlert("Playground", "Do you really want to clear all drawing objects?", "No", "Yes"); + BAlert *alert = new BAlert("Playground", + "Do you really want to clear all drawing objects?", + "No", "Yes"); if (alert->Go() == 1) { fObjectView->MakeEmpty(); + fObjectLV->MakeEmpty(); } break; } diff --git a/src/tests/servers/app/playground/States.cpp b/src/tests/servers/app/playground/States.cpp index 666f715d44..0d97bc34cb 100644 --- a/src/tests/servers/app/playground/States.cpp +++ b/src/tests/servers/app/playground/States.cpp @@ -52,7 +52,7 @@ State::MouseDown(BPoint where) // MouseUp void -State::MouseUp(BPoint where) +State::MouseUp() { fTracking = TRACKING_NONE; } diff --git a/src/tests/servers/app/playground/States.h b/src/tests/servers/app/playground/States.h index 1e5d2c69ca..3c3f51928a 100644 --- a/src/tests/servers/app/playground/States.h +++ b/src/tests/servers/app/playground/States.h @@ -26,7 +26,7 @@ class State { bool fill, float penSize); void MouseDown(BPoint where); - void MouseUp(BPoint where); + void MouseUp(); void MouseMoved(BPoint where); bool IsTracking() const { return fTracking; }