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:
@@ -37,6 +37,16 @@ ObjectView::ObjectView(BRect frame, const char* name,
|
|||||||
// font.SetSize(20.0);
|
// font.SetSize(20.0);
|
||||||
//// font.SetRotation(6.0);
|
//// font.SetRotation(6.0);
|
||||||
// SetFont(&font, B_FONT_FAMILY_AND_STYLE | B_FONT_ROTATION | B_FONT_SIZE);
|
// 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
|
// AttachedToWindow
|
||||||
@@ -77,16 +87,48 @@ ObjectView::Draw(BRect updateRect)
|
|||||||
BPoint p(r.Width() / 2.0 - width / 2.0,
|
BPoint p(r.Width() / 2.0 - width / 2.0,
|
||||||
r.Height() / 2.0);
|
r.Height() / 2.0);
|
||||||
|
|
||||||
Sync();
|
//Sync();
|
||||||
bigtime_t now = system_time();
|
//bigtime_t now = system_time();
|
||||||
DrawString(message, p);
|
DrawString(message, p);
|
||||||
|
|
||||||
Sync();
|
//Sync();
|
||||||
printf("Drawing Text: %lld\n", system_time() - now);
|
//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++)
|
for (int32 i = 0; State* state = (State*)fStateList.ItemAt(i); i++)
|
||||||
state->Draw(this);
|
state->Draw(this);
|
||||||
|
//Sync();
|
||||||
|
//printf("State: %lld\n", system_time() - start);
|
||||||
}
|
}
|
||||||
|
|
||||||
// MouseDown
|
// MouseDown
|
||||||
@@ -126,7 +168,7 @@ ObjectView::MouseUp(BPoint where)
|
|||||||
fScrolling = false;
|
fScrolling = false;
|
||||||
} else {
|
} else {
|
||||||
if (fState) {
|
if (fState) {
|
||||||
fState->MouseUp(where);
|
fState->MouseUp();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,7 +178,6 @@ void
|
|||||||
ObjectView::MouseMoved(BPoint where, uint32 transit,
|
ObjectView::MouseMoved(BPoint where, uint32 transit,
|
||||||
const BMessage* dragMessage)
|
const BMessage* dragMessage)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (dragMessage) {
|
if (dragMessage) {
|
||||||
//printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f)) - DRAG MESSAGE\n", where.x, where.y);
|
//printf("ObjectView::MouseMoved(BPoint(%.1f, %.1f)) - DRAG MESSAGE\n", where.x, where.y);
|
||||||
//Window()->CurrentMessage()->PrintToStream();
|
//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
|
// CountObjects
|
||||||
int32
|
int32
|
||||||
ObjectView::CountObjects() const
|
ObjectView::CountObjects() const
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class ObjectView : public BView {
|
|||||||
{ return fObjectType; }
|
{ return fObjectType; }
|
||||||
|
|
||||||
void AddObject(State* state);
|
void AddObject(State* state);
|
||||||
|
void RemoveObject(State* state);
|
||||||
int32 CountObjects() const;
|
int32 CountObjects() const;
|
||||||
void MakeEmpty();
|
void MakeEmpty();
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ enum {
|
|||||||
MSG_CLEAR = 'clir',
|
MSG_CLEAR = 'clir',
|
||||||
|
|
||||||
MSG_OBJECT_SELECTED = 'obsl',
|
MSG_OBJECT_SELECTED = 'obsl',
|
||||||
|
MSG_REMOVE_OBJECT = 'rmob',
|
||||||
};
|
};
|
||||||
|
|
||||||
// ObjectItem
|
// ObjectItem
|
||||||
@@ -63,6 +64,26 @@ class ObjectItem : public BStringItem {
|
|||||||
State* fObject;
|
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 -
|
// #pragma mark -
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
@@ -297,10 +318,10 @@ ObjectWindow::ObjectWindow(BRect frame, const char* name)
|
|||||||
b.top += 10.0;
|
b.top += 10.0;
|
||||||
b.InsetBy(9.0, 7.0);
|
b.InsetBy(9.0, 7.0);
|
||||||
b.left = b.left + b.Width() / 2.0 + 6.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;
|
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));
|
fObjectLV->SetSelectionMessage(new BMessage(MSG_OBJECT_SELECTED));
|
||||||
|
|
||||||
// wrap a scroll view around the list view
|
// wrap a scroll view around the list view
|
||||||
@@ -309,6 +330,20 @@ b.bottom = fDrawingModeMF->Frame().top - 5.0;
|
|||||||
B_FANCY_BORDER);
|
B_FANCY_BORDER);
|
||||||
controlGroup->AddChild(scrollView);
|
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
|
// enforce some size limits
|
||||||
float minWidth = controlGroup->Frame().Width() + 30.0;
|
float minWidth = controlGroup->Frame().Width() + 30.0;
|
||||||
float minHeight = fPenSizeS->Frame().bottom +
|
float minHeight = fPenSizeS->Frame().bottom +
|
||||||
@@ -375,19 +410,28 @@ ObjectWindow::MessageReceived(BMessage* message)
|
|||||||
fClearB->SetEnabled(fObjectView->CountObjects() > 0);
|
fClearB->SetEnabled(fObjectView->CountObjects() > 0);
|
||||||
break;
|
break;
|
||||||
case MSG_OBJECT_SELECTED:
|
case MSG_OBJECT_SELECTED:
|
||||||
printf("MSG_OBJECT_SELECTED\n");
|
|
||||||
if (ObjectItem* item = (ObjectItem*)fObjectLV->ItemAt(fObjectLV->CurrentSelection(0))) {
|
if (ObjectItem* item = (ObjectItem*)fObjectLV->ItemAt(fObjectLV->CurrentSelection(0))) {
|
||||||
fObjectView->SetState(item->Object());
|
fObjectView->SetState(item->Object());
|
||||||
} else
|
} else
|
||||||
fObjectView->SetState(NULL);
|
fObjectView->SetState(NULL);
|
||||||
break;
|
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:
|
case MSG_NEW_OBJECT:
|
||||||
fObjectView->SetState(NULL);
|
fObjectView->SetState(NULL);
|
||||||
break;
|
break;
|
||||||
case MSG_CLEAR: {
|
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) {
|
if (alert->Go() == 1) {
|
||||||
fObjectView->MakeEmpty();
|
fObjectView->MakeEmpty();
|
||||||
|
fObjectLV->MakeEmpty();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ State::MouseDown(BPoint where)
|
|||||||
|
|
||||||
// MouseUp
|
// MouseUp
|
||||||
void
|
void
|
||||||
State::MouseUp(BPoint where)
|
State::MouseUp()
|
||||||
{
|
{
|
||||||
fTracking = TRACKING_NONE;
|
fTracking = TRACKING_NONE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class State {
|
|||||||
bool fill, float penSize);
|
bool fill, float penSize);
|
||||||
|
|
||||||
void MouseDown(BPoint where);
|
void MouseDown(BPoint where);
|
||||||
void MouseUp(BPoint where);
|
void MouseUp();
|
||||||
void MouseMoved(BPoint where);
|
void MouseMoved(BPoint where);
|
||||||
bool IsTracking() const
|
bool IsTracking() const
|
||||||
{ return fTracking; }
|
{ return fTracking; }
|
||||||
|
|||||||
Reference in New Issue
Block a user