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
This commit is contained in:
Stephan Aßmus 2006-01-05 23:51:23 +00:00
parent a041f6e8f6
commit 269293b0ea
5 changed files with 115 additions and 13 deletions

View File

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

View File

@ -38,6 +38,7 @@ class ObjectView : public BView {
{ return fObjectType; }
void AddObject(State* state);
void RemoveObject(State* state);
int32 CountObjects() const;
void MakeEmpty();

View File

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

View File

@ -52,7 +52,7 @@ State::MouseDown(BPoint where)
// MouseUp
void
State::MouseUp(BPoint where)
State::MouseUp()
{
fTracking = TRACKING_NONE;
}

View File

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