From 85623bad057fb4912f355ac5a4dde05fbd471b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 9 Jul 2006 10:21:18 +0000 Subject: [PATCH] * relayout of the GUI, you can start to take it serious :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18077 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/icon-o-matic/MainWindow.cpp | 173 +++++++++++++++----- src/apps/icon-o-matic/MainWindow.h | 9 +- src/apps/icon-o-matic/gui/StyleListView.cpp | 4 +- src/apps/icon-o-matic/gui/SwatchGroup.cpp | 4 + 4 files changed, 144 insertions(+), 46 deletions(-) diff --git a/src/apps/icon-o-matic/MainWindow.cpp b/src/apps/icon-o-matic/MainWindow.cpp index 893979d41b..6d25ebcc04 100644 --- a/src/apps/icon-o-matic/MainWindow.cpp +++ b/src/apps/icon-o-matic/MainWindow.cpp @@ -61,7 +61,7 @@ enum { // constructor MainWindow::MainWindow(IconEditorApp* app, Document* document) - : BWindow(BRect(20, 50, 1010, 781), "Icon-O-Matic", + : BWindow(BRect(50, 50, 900, 750), "Icon-O-Matic", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS), fApp(app), @@ -220,8 +220,7 @@ void MainWindow::_Init() { // create the GUI - BView* topView = _CreateGUI(Bounds()); - AddChild(topView); + _CreateGUI(Bounds()); fCanvasView->SetCatchAllEvents(true); fCanvasView->SetCommandStack(fDocument->CommandStack()); @@ -247,6 +246,7 @@ MainWindow::_Init() fPropertyListView->SetCommandStack(fDocument->CommandStack()); fPropertyListView->SetSelection(fDocument->Selection()); + fPropertyListView->SetMenu(fPropertyMenu); fIconPreview16->SetIcon(fDocument->Icon()); fIconPreview32->SetIcon(fDocument->Icon()); @@ -319,26 +319,54 @@ MainWindow::_Init() } // _CreateGUI -BView* +void MainWindow::_CreateGUI(BRect bounds) { - BRect menuFrame = bounds; - menuFrame.bottom = menuFrame.top + 15; - BMenuBar* menuBar = _CreateMenuBar(menuFrame); - AddChild(menuBar); - - menuBar->ResizeToPreferred(); - bounds.top = menuBar->Frame().bottom + 1; + const float splitWidth = 150; BView* bg = new BView(bounds, "bg", B_FOLLOW_ALL, 0); bg->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(bg); - fSwatchGroup = new SwatchGroup(BRect(0, 0, 100, 100)); + BRect menuFrame = bounds; + menuFrame.bottom = menuFrame.top + 15; + BMenuBar* menuBar = _CreateMenuBar(menuFrame); + bg->AddChild(menuBar); + float menuWidth; + float menuHeight; + menuBar->GetPreferredSize(&menuWidth, &menuHeight); + menuBar->ResizeTo(splitWidth - 1, menuHeight); + menuBar->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); + + bounds.top = menuBar->Frame().bottom + 1; + + // swatch group + fSwatchGroup = new SwatchGroup(bounds); + // SwatchGroup auto resizes itself + fSwatchGroup->MoveTo(bounds.right - fSwatchGroup->Bounds().Width(), + bounds.top); + fSwatchGroup->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_TOP); + + bounds.left = fSwatchGroup->Frame().left; + bounds.right = bg->Bounds().right; + bounds.top = bg->Bounds().top; + bounds.bottom = bounds.top + menuHeight; + menuBar = new BMenuBar(bounds, "swatches menu bar"); + menuBar->AddItem(fSwatchMenu); + bg->AddChild(menuBar); + menuBar->ResizeTo(bounds.Width(), menuHeight); + // menu bars resize themselves to window width + menuBar->SetResizingMode(B_FOLLOW_RIGHT | B_FOLLOW_TOP); + + // canvas view + bounds.left = splitWidth; bounds.top = fSwatchGroup->Frame().bottom + 1; - + bounds.right = bg->Bounds().right; + bounds.bottom = bg->Bounds().bottom; fCanvasView = new CanvasView(bounds); - bounds.left = fSwatchGroup->Frame().right + 5; + // icon previews + bounds.left = 5; bounds.top = fSwatchGroup->Frame().top + 5; bounds.right = bounds.left + 15; bounds.bottom = bounds.top + 15; @@ -359,30 +387,92 @@ MainWindow::_CreateGUI(BRect bounds) bounds.bottom = bounds.top + 63; fIconPreview64 = new IconView(bounds, "icon preview 64"); + // style list view + bounds.left = fCanvasView->Frame().left; + bounds.right = bounds.left + splitWidth; + bounds.top = bg->Bounds().top; + bounds.bottom = bounds.top + menuHeight; + menuBar = new BMenuBar(bounds, "style menu bar"); + menuBar->AddItem(fStyleMenu); + bg->AddChild(menuBar); + menuBar->ResizeTo(bounds.Width(), menuHeight); + // menu bars resize themselves to window width + menuBar->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); + + bounds.right -= B_V_SCROLL_BAR_WIDTH + 1; + bounds.top = menuBar->Frame().bottom + 1; + bounds.bottom = fCanvasView->Frame().top - 1; + + fStyleListView = new StyleListView(bounds, "style list view", + new BMessage(MSG_STYLE_SELECTED), this); + + // path list view - bounds.OffsetBy(bounds.Width() + 6, 0); - bounds.right = bounds.left + 100; - bounds.bottom = fCanvasView->Frame().top - 5.0; + bounds.left = 0; + bounds.right = fCanvasView->Frame().left - 1; + bounds.top = fCanvasView->Frame().top; + bounds.bottom = bounds.top + menuHeight; + menuBar = new BMenuBar(bounds, "path menu bar"); + menuBar->AddItem(fPathMenu); + bg->AddChild(menuBar); + menuBar->ResizeTo(bounds.Width(), menuHeight); + // menu bars resize themselves to window width + menuBar->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); + + bounds.right -= B_V_SCROLL_BAR_WIDTH + 1; + bounds.top = menuBar->Frame().bottom + 1; + bounds.bottom = bounds.top + 130; fPathListView = new PathListView(bounds, "path list view", new BMessage(MSG_PATH_SELECTED), this); - // style list view - bounds.OffsetBy(bounds.Width() + 6 + B_V_SCROLL_BAR_WIDTH, 0); - fStyleListView = new StyleListView(bounds, "style list view", - new BMessage(MSG_STYLE_SELECTED), this); // shape list view - bounds.OffsetBy(bounds.Width() + 6 + B_V_SCROLL_BAR_WIDTH, 0); + bounds.right += B_V_SCROLL_BAR_WIDTH + 1; + bounds.top = fPathListView->Frame().bottom + 1; + bounds.bottom = bounds.top + menuHeight; + menuBar = new BMenuBar(bounds, "shape menu bar"); + menuBar->AddItem(fShapeMenu); + bg->AddChild(menuBar); + menuBar->ResizeTo(bounds.Width(), menuHeight); + // menu bars resize themselves to window width + menuBar->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); + + bounds.right -= B_V_SCROLL_BAR_WIDTH + 1; + bounds.top = menuBar->Frame().bottom + 1; + bounds.bottom = bounds.top + 130; + fShapeListView = new ShapeListView(bounds, "shape list view", new BMessage(MSG_SHAPE_SELECTED), this); // transformer list view - bounds.OffsetBy(bounds.Width() + 6 + B_V_SCROLL_BAR_WIDTH, 0); + bounds.right += B_V_SCROLL_BAR_WIDTH + 1; + bounds.top = fShapeListView->Frame().bottom + 1; + bounds.bottom = bounds.top + menuHeight; + menuBar = new BMenuBar(bounds, "transformer menu bar"); + menuBar->AddItem(fTransformerMenu); + bg->AddChild(menuBar); + menuBar->ResizeTo(bounds.Width(), bounds.Height()); + // menu bars resize themselves to window width + menuBar->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); + + bounds.right -= B_V_SCROLL_BAR_WIDTH + 1; + bounds.top = menuBar->Frame().bottom + 1; + bounds.bottom = bounds.top + 80; fTransformerListView = new TransformerListView(bounds, "transformer list view"); // property list view + bounds.right += B_V_SCROLL_BAR_WIDTH + 1; + bounds.top = fTransformerListView->Frame().bottom + 1; + bounds.bottom = bounds.top + menuHeight; + menuBar = new BMenuBar(bounds, "property menu bar"); + menuBar->AddItem(fPropertyMenu); + bg->AddChild(menuBar); + menuBar->ResizeTo(bounds.Width(), bounds.Height()); + // menu bars resize themselves to window width + menuBar->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); + fPropertyListView = new IconObjectListView(); bg->AddChild(fSwatchGroup); @@ -414,18 +504,16 @@ MainWindow::_CreateGUI(BRect bounds) B_NO_BORDER)); // scroll view around property list view - bounds.OffsetBy(bounds.Width() + 6 + B_V_SCROLL_BAR_WIDTH, 0); - bounds.right = bg->Bounds().right - 5; + bounds.top = menuBar->Frame().bottom + 1; + bounds.bottom = bg->Bounds().bottom; bg->AddChild(new ScrollView(fPropertyListView, SCROLL_VERTICAL | SCROLL_NO_FRAME, bounds, "property scroll view", - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, + B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW | B_FRAME_EVENTS)); bg->AddChild(fCanvasView); - - return bg; } // _CreateMenuBar @@ -436,17 +524,15 @@ MainWindow::_CreateMenuBar(BRect frame) BMenu* fileMenu = new BMenu("File"); BMenu* editMenu = new BMenu("Edit"); - BMenu* pathMenu = new BMenu("Path"); - BMenu* styleMenu = new BMenu("Style"); - BMenu* shapeMenu = new BMenu("Shape"); - BMenu* transformerMenu = new BMenu("Transformer"); + fPathMenu = new BMenu("Path"); + fStyleMenu = new BMenu("Style"); + fShapeMenu = new BMenu("Shape"); + fTransformerMenu = new BMenu("Transformer"); + fPropertyMenu = new BMenu("Property"); + fSwatchMenu = new BMenu("Swatches"); menuBar->AddItem(fileMenu); menuBar->AddItem(editMenu); - menuBar->AddItem(pathMenu); - menuBar->AddItem(styleMenu); - menuBar->AddItem(shapeMenu); - menuBar->AddItem(transformerMenu); // Edit fUndoMI = new BMenuItem("", @@ -461,26 +547,27 @@ MainWindow::_CreateMenuBar(BRect frame) editMenu->AddItem(fRedoMI); // Path - pathMenu->AddItem(new BMenuItem("New", new BMessage(MSG_NEW_PATH))); + fPathMenu->AddItem(new BMenuItem("New", new BMessage(MSG_NEW_PATH))); // Style - styleMenu->AddItem(new BMenuItem("New", new BMessage(MSG_NEW_STYLE))); + fStyleMenu->AddItem(new BMenuItem("New", new BMessage(MSG_NEW_STYLE))); // Shape - shapeMenu->AddItem(new BMenuItem("New", new BMessage(MSG_NEW_SHAPE))); + fShapeMenu->AddItem(new BMenuItem("New", new BMessage(MSG_NEW_SHAPE))); + // Transformer + 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); - BString label("Add "); - label << name; - transformerMenu->AddItem(new BMenuItem(label.String(), message)); + addMenu->AddItem(new BMenuItem(name.String(), message)); } - transformerMenu->SetTargetForItems(this); + addMenu->SetTargetForItems(this); + fTransformerMenu->AddItem(addMenu); return menuBar; } diff --git a/src/apps/icon-o-matic/MainWindow.h b/src/apps/icon-o-matic/MainWindow.h index a823302bf5..c5f45d0ffc 100644 --- a/src/apps/icon-o-matic/MainWindow.h +++ b/src/apps/icon-o-matic/MainWindow.h @@ -44,12 +44,19 @@ class MainWindow : public BWindow, private: void _Init(); - BView* _CreateGUI(BRect frame); + void _CreateGUI(BRect frame); BMenuBar* _CreateMenuBar(BRect frame); IconEditorApp* fApp; Document* fDocument; + BMenu* fPathMenu; + BMenu* fStyleMenu; + BMenu* fShapeMenu; + BMenu* fTransformerMenu; + BMenu* fPropertyMenu; + BMenu* fSwatchMenu; + BMenuItem* fUndoMI; BMenuItem* fRedoMI; diff --git a/src/apps/icon-o-matic/gui/StyleListView.cpp b/src/apps/icon-o-matic/gui/StyleListView.cpp index 4f3c8a4244..5d70096086 100644 --- a/src/apps/icon-o-matic/gui/StyleListView.cpp +++ b/src/apps/icon-o-matic/gui/StyleListView.cpp @@ -258,9 +258,9 @@ StyleListView::SelectionChanged() StyleListItem* item = dynamic_cast(ItemAt(CurrentSelection(0))); - if (item && fMessage) { + if (fMessage) { BMessage message(*fMessage); - message.AddPointer("style", (void*)item->style); + message.AddPointer("style", item ? (void*)item->style : NULL); Invoke(&message); } diff --git a/src/apps/icon-o-matic/gui/SwatchGroup.cpp b/src/apps/icon-o-matic/gui/SwatchGroup.cpp index 5d34726d49..9fa180546f 100644 --- a/src/apps/icon-o-matic/gui/SwatchGroup.cpp +++ b/src/apps/icon-o-matic/gui/SwatchGroup.cpp @@ -68,6 +68,7 @@ SwatchGroup::SwatchGroup(BRect frame) this, color, SWATCH_VIEW_WIDTH, SWATCH_VIEW_HEIGHT); + fSwatchViews[i]->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); if (i < 10) fTopSwatchViews->AddChild(fSwatchViews[i]); else @@ -87,8 +88,10 @@ SwatchGroup::SwatchGroup(BRect frame) // layout gui fTopSwatchViews->SetSpacing(0, 0); fTopSwatchViews->ResizeToPreferred(); + fTopSwatchViews->SetResizingMode(B_FOLLOW_ALL); fBottomSwatchViews->SetSpacing(0, 0); fBottomSwatchViews->ResizeToPreferred(); + fBottomSwatchViews->SetResizingMode(B_FOLLOW_ALL); fTopSwatchViews->MoveTo(30, 4); fBottomSwatchViews->MoveTo(30, fTopSwatchViews->Frame().bottom + 1); @@ -96,6 +99,7 @@ SwatchGroup::SwatchGroup(BRect frame) fCurrentColorSV->MoveTo(0, fTopSwatchViews->Frame().top); fCurrentColorSV->ResizeTo(28, fBottomSwatchViews->Frame().bottom - fTopSwatchViews->Frame().top); + fCurrentColorSV->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); float width = fTopSwatchViews->Frame().right - fCurrentColorSV->Frame().left;