* various UI improvements and fixes

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19347 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2006-11-21 09:37:50 +00:00
parent 31a0d05b20
commit 84153c7a0c
8 changed files with 173 additions and 54 deletions
+1 -45
View File
@@ -29,7 +29,6 @@
#include "AddPathsCommand.h" #include "AddPathsCommand.h"
#include "AddShapesCommand.h" #include "AddShapesCommand.h"
#include "AddStylesCommand.h" #include "AddStylesCommand.h"
#include "AddTransformersCommand.h"
#include "CanvasView.h" #include "CanvasView.h"
#include "CommandStack.h" #include "CommandStack.h"
#include "CompoundCommand.h" #include "CompoundCommand.h"
@@ -45,7 +44,6 @@
#include "StyleListView.h" #include "StyleListView.h"
#include "StyleView.h" #include "StyleView.h"
#include "SwatchGroup.h" #include "SwatchGroup.h"
#include "TransformerFactory.h"
#include "TransformerListView.h" #include "TransformerListView.h"
#include "TransformGradientBox.h" #include "TransformGradientBox.h"
#include "TransformShapesBox.h" #include "TransformShapesBox.h"
@@ -78,8 +76,6 @@ enum {
MSG_SHAPE_RESET_TRANSFORMATION = 'rtsh', MSG_SHAPE_RESET_TRANSFORMATION = 'rtsh',
MSG_STYLE_RESET_TRANSFORMATION = 'rtst', MSG_STYLE_RESET_TRANSFORMATION = 'rtst',
MSG_ADD_TRANSFORMER = 'adtr',
MSG_MOUSE_FILTER_MODE = 'mfmd', MSG_MOUSE_FILTER_MODE = 'mfmd',
}; };
@@ -268,7 +264,6 @@ case MSG_SHAPE_SELECTED: {
fState->DeleteManipulators(); fState->DeleteManipulators();
if (selectedShapes.CountItems() > 0) { if (selectedShapes.CountItems() > 0) {
printf("selected shapes: %ld\n", selectedShapes.CountItems());
TransformShapesBox* transformBox = new (nothrow) TransformShapesBox( TransformShapesBox* transformBox = new (nothrow) TransformShapesBox(
fCanvasView, fCanvasView,
(const Shape**)selectedShapes.Items(), (const Shape**)selectedShapes.Items(),
@@ -277,33 +272,6 @@ printf("selected shapes: %ld\n", selectedShapes.CountItems());
} }
break; break;
} }
case MSG_ADD_TRANSFORMER: {
Shape* shape = fPathListView->CurrentShape();
if (!shape)
break;
uint32 type;
if (message->FindInt32("type", (int32*)&type) < B_OK)
break;
Transformer* transformer
= TransformerFactory::TransformerFor(type,
shape->VertexSource());
if (!transformer)
break;
Transformer* transformers[1];
transformers[0] = transformer;
::Command* command = new (nothrow) AddTransformersCommand(
shape, transformers, 1, shape->CountTransformers());
if (!command)
delete transformer;
fDocument->CommandStack()->Perform(command);
break;
}
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
} }
@@ -499,6 +467,7 @@ MainWindow::_Init()
fShapeListView->SetCommandStack(fDocument->CommandStack()); fShapeListView->SetCommandStack(fDocument->CommandStack());
fShapeListView->SetSelection(fDocument->Selection()); fShapeListView->SetSelection(fDocument->Selection());
fTransformerListView->SetMenu(fTransformerMenu);
fTransformerListView->SetCommandStack(fDocument->CommandStack()); fTransformerListView->SetCommandStack(fDocument->CommandStack());
fTransformerListView->SetSelection(fDocument->Selection()); fTransformerListView->SetSelection(fDocument->Selection());
@@ -1019,19 +988,6 @@ MainWindow::_CreateMenuBar(BRect frame)
settingsMenu->AddItem(filterModeMenu); settingsMenu->AddItem(filterModeMenu);
// Transformer
BMenu* addMenu = new BMenu("Add");
int32 cookie = 0;
uint32 type;
BString name;
while (TransformerFactory::NextType(&cookie, &type, &name)) {
message = new BMessage(MSG_ADD_TRANSFORMER);
message->AddInt32("type", type);
addMenu->AddItem(new BMenuItem(name.String(), message));
}
addMenu->SetTargetForItems(this);
fTransformerMenu->AddItem(addMenu);
return menuBar; return menuBar;
} }
@@ -131,6 +131,7 @@ void
PropertyListView::FrameResized(float width, float height) PropertyListView::FrameResized(float width, float height)
{ {
SetVisibleSize(width, height); SetVisibleSize(width, height);
Invalidate();
} }
// Draw // Draw
@@ -422,6 +423,7 @@ PropertyListView::SetTo(PropertyObject* object)
_UpdateSavedProperties(); _UpdateSavedProperties();
_CheckMenuStatus(); _CheckMenuStatus();
Invalidate();
} }
// PropertyChanged // PropertyChanged
@@ -666,9 +668,15 @@ PropertyListView::_LayoutItems()
void void
PropertyListView::_CheckMenuStatus() PropertyListView::_CheckMenuStatus()
{ {
if (!fPropertyM || !fSuspendUpdates) if (!fPropertyM || fSuspendUpdates)
return; return;
if (!fPropertyObject) {
fPropertyM->SetEnabled(false);
return;
} else
fPropertyM->SetEnabled(false);
bool gotSelection = false; bool gotSelection = false;
for (int32 i = 0; PropertyItemView* item = _ItemAt(i); i++) { for (int32 i = 0; PropertyItemView* item = _ItemAt(i); i++) {
if (item->IsSelected()) { if (item->IsSelected()) {
@@ -39,6 +39,40 @@ IconObjectListView::~IconObjectListView()
_SetObject(NULL); _SetObject(NULL);
} }
// Draw
void
IconObjectListView::Draw(BRect updateRect)
{
PropertyListView::Draw(updateRect);
if (fObject)
return;
// display helpful messages
const char* message1 = "Click on an object in";
const char* message2 = "any of the other lists to";
const char* message3 = "edit it's properties here.";
SetHighColor(tint_color(LowColor(), B_DARKEN_2_TINT));
font_height fh;
GetFontHeight(&fh);
BRect b(Bounds());
BPoint middle;
float textHeight = (fh.ascent + fh.descent) * 1.5;
middle.y = (b.top + b.bottom) / 2.0 - textHeight;
middle.x = (b.left + b.right - StringWidth(message1)) / 2.0;
DrawString(message1, middle);
middle.y += textHeight;
middle.x = (b.left + b.right - StringWidth(message2)) / 2.0;
DrawString(message2, middle);
middle.y += textHeight;
middle.x = (b.left + b.right - StringWidth(message3)) / 2.0;
DrawString(message3, middle);
}
// PropertyChanged // PropertyChanged
void void
IconObjectListView::PropertyChanged(const Property* previous, IconObjectListView::PropertyChanged(const Property* previous,
@@ -23,6 +23,8 @@ class IconObjectListView : public PropertyListView,
virtual ~IconObjectListView(); virtual ~IconObjectListView();
// PropertyListView interface // PropertyListView interface
virtual void Draw(BRect updateRect);
virtual void PropertyChanged(const Property* previous, virtual void PropertyChanged(const Property* previous,
const Property* current); const Property* current);
virtual void PasteProperties(const PropertyObject* object); virtual void PasteProperties(const PropertyObject* object);
+9 -4
View File
@@ -153,6 +153,8 @@ StyleView::StyleView(BRect frame)
AddChild(fGradientControl); AddChild(fGradientControl);
#endif // __HAIKU__ #endif // __HAIKU__
fStyleType->SetEnabled(false);
fGradientType->SetEnabled(false);
fGradientControl->SetEnabled(false); fGradientControl->SetEnabled(false);
fGradientControl->Gradient()->AddObserver(this); fGradientControl->Gradient()->AddObserver(this);
} }
@@ -295,9 +297,12 @@ StyleView::SetStyle(Style* style)
if (fCurrentColor && !gradient) if (fCurrentColor && !gradient)
fCurrentColor->SetColor(fStyle->Color()); fCurrentColor->SetColor(fStyle->Color());
}
_SetGradient(gradient); fStyleType->SetEnabled(true);
} else
fStyleType->SetEnabled(false);
_SetGradient(gradient, true);
} }
// SetCommandStack // SetCommandStack
@@ -327,9 +332,9 @@ StyleView::SetCurrentColor(CurrentColor* color)
// _SetGradient // _SetGradient
void void
StyleView::_SetGradient(Gradient* gradient) StyleView::_SetGradient(Gradient* gradient, bool forceControlUpdate)
{ {
if (fGradient == gradient) if (!forceControlUpdate && fGradient == gradient)
return; return;
if (fGradient) if (fGradient)
+2 -1
View File
@@ -50,7 +50,8 @@ class StyleView : public BView,
void SetCurrentColor(CurrentColor* color); void SetCurrentColor(CurrentColor* color);
private: private:
void _SetGradient(Gradient* gradient); void _SetGradient(Gradient* gradient,
bool forceControlUpdate = false);
void _MarkType(BMenu* menu, void _MarkType(BMenu* menu,
int32 type) const; int32 type) const;
void _SetStyleType(int32 type); void _SetStyleType(int32 type);
@@ -13,14 +13,18 @@
#include <Application.h> #include <Application.h>
#include <ListItem.h> #include <ListItem.h>
#include <Message.h> #include <Menu.h>
#include <MenuItem.h>
#include <Mime.h> #include <Mime.h>
#include <Message.h>
#include <Window.h> #include <Window.h>
#include "AddTransformersCommand.h"
#include "CommandStack.h" #include "CommandStack.h"
#include "MoveTransformersCommand.h" #include "MoveTransformersCommand.h"
#include "RemoveTransformersCommand.h" #include "RemoveTransformersCommand.h"
#include "Transformer.h" #include "Transformer.h"
#include "TransformerFactory.h"
#include "Observer.h" #include "Observer.h"
#include "Selection.h" #include "Selection.h"
@@ -87,7 +91,8 @@ class TransformerItem : public SimpleItem,
// #pragma mark - // #pragma mark -
enum { enum {
MSG_DRAG_TRANSFORMER = 'drgt', MSG_DRAG_TRANSFORMER = 'drgt',
MSG_ADD_TRANSFORMER = 'adtr',
}; };
// constructor // constructor
@@ -113,6 +118,35 @@ TransformerListView::~TransformerListView()
fShape->RemoveListener(this); fShape->RemoveListener(this);
} }
// Draw
void
TransformerListView::Draw(BRect updateRect)
{
SimpleListView::Draw(updateRect);
if (fShape)
return;
// display helpful messages
const char* message1 = "Click on a shape above";
const char* message2 = "to attach Transformers.";
SetHighColor(tint_color(LowColor(), B_DARKEN_2_TINT));
font_height fh;
GetFontHeight(&fh);
BRect b(Bounds());
BPoint middle;
float textHeight = (fh.ascent + fh.descent) * 1.5;
middle.y = (b.top + b.bottom - textHeight) / 2.0;
middle.x = (b.left + b.right - StringWidth(message1)) / 2.0;
DrawString(message1, middle);
middle.y += textHeight;
middle.x = (b.left + b.right - StringWidth(message2)) / 2.0;
DrawString(message2, middle);
}
// SelectionChanged // SelectionChanged
void void
TransformerListView::SelectionChanged() TransformerListView::SelectionChanged()
@@ -134,6 +168,42 @@ TransformerListView::SelectionChanged()
} }
} }
// MessageReceived
void
TransformerListView::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_ADD_TRANSFORMER: {
if (!fShape || !fCommandStack)
break;
uint32 type;
if (message->FindInt32("type", (int32*)&type) < B_OK)
break;
Transformer* transformer
= TransformerFactory::TransformerFor(type,
fShape->VertexSource());
if (!transformer)
break;
Transformer* transformers[1];
transformers[0] = transformer;
::Command* command = new (nothrow) AddTransformersCommand(
fShape, transformers, 1, fShape->CountTransformers());
if (!command)
delete transformer;
fCommandStack->Perform(command);
break;
}
default:
SimpleListView::MessageReceived(message);
break;
}
}
// MakeDragMessage // MakeDragMessage
void void
TransformerListView::MakeDragMessage(BMessage* message) const TransformerListView::MakeDragMessage(BMessage* message) const
@@ -289,6 +359,32 @@ TransformerListView::StyleChanged(Style* oldStyle, Style* newStyle)
// #pragma mark - // #pragma mark -
// SetMenu
void
TransformerListView::SetMenu(BMenu* menu)
{
if (fMenu == menu)
return;
fMenu = menu;
if (fMenu == NULL)
return;
BMenu* addMenu = new BMenu("Add");
int32 cookie = 0;
uint32 type;
BString name;
while (TransformerFactory::NextType(&cookie, &type, &name)) {
BMessage* message = new BMessage(MSG_ADD_TRANSFORMER);
message->AddInt32("type", type);
addMenu->AddItem(new BMenuItem(name.String(), message));
}
addMenu->SetTargetForItems(this);
fMenu->AddItem(addMenu);
_UpdateMenu();
}
// SetShape // SetShape
void void
TransformerListView::SetShape(Shape* shape) TransformerListView::SetShape(Shape* shape)
@@ -312,6 +408,8 @@ TransformerListView::SetShape(Shape* shape)
int32 count = fShape->CountTransformers(); int32 count = fShape->CountTransformers();
for (int32 i = 0; i < count; i++) for (int32 i = 0; i < count; i++)
_AddTransformer(fShape->TransformerAtFast(i), i); _AddTransformer(fShape->TransformerAtFast(i), i);
_UpdateMenu();
} }
// SetCommandStack // SetCommandStack
@@ -357,4 +455,9 @@ TransformerListView::_ItemForTransformer(Transformer* transformer) const
return NULL; return NULL;
} }
// _UpdateMenu
void
TransformerListView::_UpdateMenu()
{
fMenu->SetEnabled(fShape != NULL);
}
@@ -12,6 +12,7 @@
#include "ListViews.h" #include "ListViews.h"
#include "Shape.h" #include "Shape.h"
class BMenu;
class CommandStack; class CommandStack;
class Transformer; class Transformer;
class TransformerItem; class TransformerItem;
@@ -27,8 +28,12 @@ class TransformerListView : public SimpleListView,
virtual ~TransformerListView(); virtual ~TransformerListView();
// SimpleListView interface // SimpleListView interface
virtual void Draw(BRect updateRect);
virtual void SelectionChanged(); virtual void SelectionChanged();
virtual void MessageReceived(BMessage* message);
virtual void MakeDragMessage(BMessage* message) const; virtual void MakeDragMessage(BMessage* message) const;
virtual void MoveItems(BList& items, int32 toIndex); virtual void MoveItems(BList& items, int32 toIndex);
@@ -48,6 +53,7 @@ class TransformerListView : public SimpleListView,
virtual void StyleChanged(Style* oldStyle, Style* newStyle); virtual void StyleChanged(Style* oldStyle, Style* newStyle);
// TransformerListView // TransformerListView
void SetMenu(BMenu* menu);
void SetShape(Shape* shape); void SetShape(Shape* shape);
void SetCommandStack(CommandStack* stack); void SetCommandStack(CommandStack* stack);
@@ -60,10 +66,14 @@ class TransformerListView : public SimpleListView,
TransformerItem* _ItemForTransformer( TransformerItem* _ItemForTransformer(
Transformer* transformer) const; Transformer* transformer) const;
void _UpdateMenu();
BMessage* fMessage; BMessage* fMessage;
Shape* fShape; Shape* fShape;
CommandStack* fCommandStack; CommandStack* fCommandStack;
BMenu* fMenu;
}; };
#endif // TRANSFORMER_LIST_VIEW_H #endif // TRANSFORMER_LIST_VIEW_H