* started work on saving program settins, window frame is

remembered for now
* fixed some annoying bugs:
- the snapping prevented some of the proximity checks from
  working while editing a path or using the transform box,
  now the Manipulators themself are responsible for mouse
  snapping and can do so at the time it works best for them
- pressing the Esc key while using the transform box did
  reset the transformation, but didn't exit the transform
  mode (return to path editing)
* improved layout of some views when the window is resized



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19266 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2006-11-12 22:24:39 +00:00
parent 7743580815
commit 4fac07a088
15 changed files with 249 additions and 87 deletions

View File

@ -126,20 +126,48 @@ CanvasView::MouseDown(BPoint where)
if (!IsFocus())
MakeFocus(true);
_FilterMouse(&where);
StateView::MouseDown(where);
}
// MouseMoved
// FilterMouse
void
CanvasView::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage)
CanvasView::FilterMouse(BPoint* where) const
{
_FilterMouse(&where);
switch (fMouseFilterMode) {
StateView::MouseMoved(where, transit, dragMessage);
case SNAPPING_64:
ConvertToCanvas(where);
where->x = floorf(where->x + 0.5);
where->y = floorf(where->y + 0.5);
ConvertFromCanvas(where);
break;
case SNAPPING_32:
ConvertToCanvas(where);
where->x /= 2.0;
where->y /= 2.0;
where->x = floorf(where->x + 0.5);
where->y = floorf(where->y + 0.5);
where->x *= 2.0;
where->y *= 2.0;
ConvertFromCanvas(where);
break;
case SNAPPING_16:
ConvertToCanvas(where);
where->x /= 4.0;
where->y /= 4.0;
where->x = floorf(where->x + 0.5);
where->y = floorf(where->y + 0.5);
where->x *= 4.0;
where->y *= 4.0;
ConvertFromCanvas(where);
break;
case SNAPPING_OFF:
default:
break;
}
}
// #pragma mark -
@ -387,47 +415,6 @@ CanvasView::_DrawInto(BView* view, BRect updateRect)
StateView::Draw(view, updateRect);
}
// _FilterMouse
void
CanvasView::_FilterMouse(BPoint* where) const
{
switch (fMouseFilterMode) {
case SNAPPING_64:
ConvertToCanvas(where);
where->x = floorf(where->x + 0.5);
where->y = floorf(where->y + 0.5);
ConvertFromCanvas(where);
break;
case SNAPPING_32:
ConvertToCanvas(where);
where->x /= 2.0;
where->y /= 2.0;
where->x = floorf(where->x + 0.5);
where->y = floorf(where->y + 0.5);
where->x *= 2.0;
where->y *= 2.0;
ConvertFromCanvas(where);
break;
case SNAPPING_16:
ConvertToCanvas(where);
where->x /= 4.0;
where->y /= 4.0;
where->x = floorf(where->x + 0.5);
where->y = floorf(where->y + 0.5);
where->x *= 4.0;
where->y *= 4.0;
ConvertFromCanvas(where);
break;
case SNAPPING_OFF:
default:
break;
}
}
// _MakeBackground
void
CanvasView::_MakeBackground()

View File

@ -36,8 +36,7 @@ class CanvasView : public StateView,
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint where);
virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage);
virtual void FilterMouse(BPoint* where) const;
// Scrollable interface
protected:
@ -80,8 +79,6 @@ class CanvasView : public StateView,
void _DrawInto(BView* view,
BRect updateRect);
void _FilterMouse(BPoint* where) const;
void _MakeBackground();
private:

View File

@ -8,15 +8,17 @@
#include "IconEditorApp.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include <Alert.h>
#include <Directory.h>
#include <Entry.h>
#include <File.h>
#include <FilePanel.h>
#include <new>
#include <stdio.h>
#include <string.h>
#include "support_settings.h"
#include "AutoLocker.h"
#include "BitmapExporter.h"
@ -44,7 +46,11 @@ IconEditorApp::IconEditorApp()
fDocument(new Document("test")),
fOpenPanel(NULL),
fSavePanel(NULL)
fSavePanel(NULL),
fLastOpenPath(""),
fLastSavePath(""),
fLastExportPath("")
{
}
@ -67,6 +73,8 @@ bool
IconEditorApp::QuitRequested()
{
// TODO: ask main window if quitting is ok
_StoreSettings();
fMainWindow->Lock();
fMainWindow->Quit();
fMainWindow = NULL;
@ -214,6 +222,9 @@ IconEditorApp::ReadyToRun()
// create main window
fMainWindow = new MainWindow(this, fDocument);
_RestoreSettings();
fMainWindow->Show();
}
@ -329,11 +340,31 @@ IconEditorApp::_Open(const entry_ref& ref, bool append)
if (mainWindowLocked)
fMainWindow->SetIcon(NULL);
fDocument->MakeEmpty();
// incorporate the loaded icon into the document
// (either replace it or append to it)
if (append) {
// preserve the entry_refs
entry_ref saveRef;
if (fDocument->Ref())
saveRef = *fDocument->Ref();
entry_ref exportRef;
if (fDocument->ExportRef())
exportRef = *fDocument->ExportRef();
fDocument->SetIcon(icon);
fDocument->MakeEmpty();
fDocument->SetIcon(icon);
if (!append) {
// restore refs after "append"
if (saveRef.name)
fDocument->SetRef(saveRef);
if (exportRef.name)
fDocument->SetExportRef(exportRef);
} else {
fDocument->MakeEmpty();
fDocument->SetIcon(icon);
// document got replaced, but we have at
// least one ref already
switch (refMode) {
case REF_MESSAGE:
fDocument->SetRef(ref);
@ -443,3 +474,65 @@ IconEditorApp::_SyncPanels(BFilePanel* from, BFilePanel* to)
from->Window()->Unlock();
}
}
// _LastFilePath
const char*
IconEditorApp::_LastFilePath(path_kind which)
{
const char* path = NULL;
switch (which) {
case LAST_PATH_OPEN:
if (fLastOpenPath.Length() > 0)
path = fLastOpenPath.String();
else if (fLastSavePath.Length() > 0)
path = fLastSavePath.String();
else if (fLastExportPath.Length() > 0)
path = fLastExportPath.String();
break;
case LAST_PATH_SAVE:
if (fLastSavePath.Length() > 0)
path = fLastSavePath.String();
else if (fLastExportPath.Length() > 0)
path = fLastExportPath.String();
else if (fLastOpenPath.Length() > 0)
path = fLastOpenPath.String();
break;
case LAST_PATH_EXPORT:
if (fLastExportPath.Length() > 0)
path = fLastExportPath.String();
else if (fLastSavePath.Length() > 0)
path = fLastSavePath.String();
else if (fLastOpenPath.Length() > 0)
path = fLastOpenPath.String();
break;
}
if (!path)
path = "/boot/home";
return path;
}
// #pragma mark -
// _StoreSettings
void
IconEditorApp::_StoreSettings()
{
BMessage settings('stns');
fMainWindow->StoreSettings(&settings);
save_settings(&settings, "Icon-O-Matic");
}
// _RestoreSettings
void
IconEditorApp::_RestoreSettings()
{
BMessage settings('stns');
load_settings(&settings, "Icon-O-Matic");
fMainWindow->RestoreSettings(&settings);
}

View File

@ -10,6 +10,7 @@
#define ICON_EDITOR_APP_H
#include <Application.h>
#include <String.h>
class BFilePanel;
class Document;
@ -49,6 +50,12 @@ enum {
EXPORT_MODE_ICON_RDEF,
};
typedef enum {
LAST_PATH_OPEN = 0,
LAST_PATH_SAVE,
LAST_PATH_EXPORT,
} path_kind;
class IconEditorApp : public BApplication {
public:
IconEditorApp();
@ -73,11 +80,20 @@ class IconEditorApp : public BApplication {
void _SyncPanels(BFilePanel* from,
BFilePanel* to);
const char* _LastFilePath(path_kind which);
void _StoreSettings();
void _RestoreSettings();
MainWindow* fMainWindow;
Document* fDocument;
BFilePanel* fOpenPanel;
BFilePanel* fSavePanel;
BString fLastOpenPath;
BString fLastSavePath;
BString fLastExportPath;
};
#endif // ICON_EDITOR_APP_H

View File

@ -188,6 +188,7 @@ Application Icon-O-Matic :
RWLocker.cpp
support.cpp
support_ui.cpp
support_settings.cpp
# gui
GradientControl.cpp

View File

@ -24,6 +24,8 @@
# include <GroupView.h>
#endif
#include "support_ui.h"
#include "AddPathsCommand.h"
#include "AddShapesCommand.h"
#include "AddStylesCommand.h"
@ -445,6 +447,28 @@ MainWindow::SetIcon(Icon* icon)
// #pragma mark -
// StoreSettings
void
MainWindow::StoreSettings(BMessage* archive)
{
if (archive->ReplaceRect("main window frame", Frame()) < B_OK)
archive->AddRect("main window frame", Frame());
}
// RestoreSettings
void
MainWindow::RestoreSettings(BMessage* archive)
{
BRect frame;
if (archive->FindRect("main window frame", &frame) == B_OK) {
make_sure_frame_is_on_screen(frame, this);
MoveTo(frame.LeftTop());
ResizeTo(frame.Width(), frame.Height());
}
}
// #pragma mark -
// _Init
void
MainWindow::_Init()
@ -795,6 +819,7 @@ MainWindow::_CreateGUI(BRect bounds)
bounds.right = fSwatchGroup->Frame().left - 1;
bounds.bottom = fCanvasView->Frame().top - 1;
fStyleView = new StyleView(bounds);
fStyleView->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
bg->AddChild(fStyleView);
// path list view

View File

@ -56,9 +56,11 @@ class MainWindow : public BWindow,
// MainWindow
void MakeEmpty();
void SetIcon(Icon* icon);
void StoreSettings(BMessage* archive);
void RestoreSettings(BMessage* archive);
private:
void _Init();
void _CreateGUI(BRect frame);

View File

@ -397,6 +397,12 @@ StateView::HandleKeyUp(uint32 key, uint32 modifiers)
return false;
}
// FilterMouse
void
StateView::FilterMouse(BPoint* where) const
{
}
// StateForDragMessage
ViewState*
StateView::StateForDragMessage(const BMessage* message)

View File

@ -51,6 +51,8 @@ class StateView : public BView {
const mouse_info* MouseInfo() const
{ return &fMouseInfo; }
virtual void FilterMouse(BPoint* where) const;
virtual ViewState* StateForDragMessage(const BMessage* message);
void SetLocker(RWLocker* locker);

View File

@ -134,24 +134,36 @@ make_color_drop_message(rgb_color color, BBitmap* bitmap)
void
make_sure_frame_is_on_screen(BRect& frame, BWindow* window)
{
BScreen screen(window);
if (frame.IsValid() && screen.IsValid()) {
if (!screen.Frame().Contains(frame)) {
// make sure frame fits in the screen
if (frame.Width() > screen.Frame().Width())
frame.right -= frame.Width() - screen.Frame().Width() + 10.0;
if (frame.Height() > screen.Frame().Height())
frame.bottom -= frame.Height() - screen.Frame().Height() + 30.0;
// frame is now at the most the size of the screen
if (frame.right > screen.Frame().right)
frame.OffsetBy(-(frame.right - screen.Frame().right), 0.0);
if (frame.bottom > screen.Frame().bottom)
frame.OffsetBy(0.0, -(frame.bottom - screen.Frame().bottom));
if (frame.left < screen.Frame().left)
frame.OffsetBy((screen.Frame().left - frame.left), 0.0);
if (frame.top < screen.Frame().top)
frame.OffsetBy(0.0, (screen.Frame().top - frame.top));
}
if (!frame.IsValid())
return;
BRect screenFrame;
if (window) {
BScreen screen(window);
if (!screen.IsValid())
return;
screenFrame = screen.Frame();
} else {
BScreen screen(B_MAIN_SCREEN_ID);
if (!screen.IsValid())
return;
screenFrame = screen.Frame();
}
if (!screenFrame.Contains(frame)) {
// make sure frame fits in the screen
if (frame.Width() > screenFrame.Width())
frame.right -= frame.Width() - screenFrame.Width() + 10.0;
if (frame.Height() > screenFrame.Height())
frame.bottom -= frame.Height() - screenFrame.Height() + 30.0;
// frame is now at the most the size of the screen
if (frame.right > screenFrame.right)
frame.OffsetBy(-(frame.right - screenFrame.right), 0.0);
if (frame.bottom > screenFrame.bottom)
frame.OffsetBy(0.0, -(frame.bottom - screenFrame.bottom));
if (frame.left < screenFrame.left)
frame.OffsetBy((screenFrame.left - frame.left), 0.0);
if (frame.top < screenFrame.top)
frame.OffsetBy(0.0, (screenFrame.top - frame.top));
}
}

View File

@ -87,6 +87,7 @@ StyleView::StyleView(BRect frame)
fStyleType->MenuBar()->GetPreferredSize(&width, &height);
fStyleType->MenuBar()->ResizeTo(width, height);
fStyleType->ResizeTo(frame.Width(), height + 6);
fStyleType->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
#endif // __HAIKU__
// gradient type
@ -133,6 +134,7 @@ StyleView::StyleView(BRect frame)
fGradientType->MenuBar()->GetPreferredSize(&width, &height);
fGradientType->MenuBar()->ResizeTo(width, height);
fGradientType->ResizeTo(frame.Width(), height + 6);
fGradientType->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
// create gradient control
frame.top = fGradientType->Frame().bottom + 8;
@ -146,6 +148,7 @@ StyleView::StyleView(BRect frame)
fGradientControl->ResizeTo(width, height);
fGradientControl->FrameResized(width, height);
fGradientControl->MoveTo(frame.left, frame.top);
fGradientControl->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT);
AddChild(fGradientControl);
#endif // __HAIKU__

View File

@ -119,6 +119,7 @@ SwatchGroup::SwatchGroup(BRect frame)
fColorField->MoveTo(0, fBottomSwatchViews->Frame().bottom + 3);
fColorSlider->MoveTo(0, fColorField->Frame().bottom + 1);
fAlphaSlider->MoveTo(0, fColorSlider->Frame().bottom + 1);
fAlphaSlider->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
// configure self
ResizeTo(width, fAlphaSlider->Frame().bottom + 4);

View File

@ -107,7 +107,8 @@ RDefExporter::_Export(const uint8* source, size_t sourceSize, BPositionIO* strea
}
}
// last line (up to 32 values)
if (ret >= B_OK) {
bool endQuotes = sourceSize > 0;
if (ret >= B_OK && sourceSize > 0) {
for (size_t i = 0; i < sourceSize; i++) {
sprintf(buffer, "%.2X", b[i]);
size = strlen(buffer);
@ -122,8 +123,8 @@ RDefExporter::_Export(const uint8* source, size_t sourceSize, BPositionIO* strea
}
}
if (ret >= B_OK) {
// finish (-> sourceSize - 1)
sprintf(buffer, "\"\n};\n");
// finish
sprintf(buffer, endQuotes ? "\"\n};\n" : "};\n");
size = strlen(buffer);
written = stream->Write(buffer, size);
if (written != (ssize_t)size) {

View File

@ -413,12 +413,17 @@ PathManipulator::MouseDown(BPoint where)
fMode = TRANSLATE_POINTS;
}
// apply the canvas view mouse filter depending on current mode
if (fMode == ADD_POINT || fMode == TRANSLATE_POINTS)
fCanvasView->FilterMouse(&where);
BPoint canvasWhere = where;
fCanvasView->ConvertToCanvas(&canvasWhere);
// maybe we're changing some point, so we construct the
// "ChangePointCommand" here so that the point is remembered
// in its current state
// apply the canvas view mouse filter depending on current mode
delete fChangePointCommand;
fChangePointCommand = NULL;
switch (fMode) {
@ -539,6 +544,9 @@ PathManipulator::MouseDown(BPoint where)
void
PathManipulator::MouseMoved(BPoint where)
{
fCanvasView->FilterMouse(&where);
// NOTE: only filter mouse coords in mouse moved, no other
// mouse function
BPoint canvasWhere = where;
fCanvasView->ConvertToCanvas(&canvasWhere);
@ -870,19 +878,19 @@ PathManipulator::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command)
// commit
case B_RETURN:
if (fTransformBox) {
_SetModeForMousePos(fLastCanvasPos);
} else
_SetTransformBox(NULL);
}// else
// _Perform();
break;
// cancel
case B_ESCAPE:
if (fTransformBox) {
fTransformBox->Cancel();
_SetModeForMousePos(fLastCanvasPos);
_SetTransformBox(NULL);
} else if (fFallBackMode == NEW_PATH) {
fFallBackMode = SELECT_POINTS;
_SetModeForMousePos(fLastCanvasPos);
} else
_SetTransformBox(NULL);
}// else
// _Cancel();
break;
case 't':
@ -1165,6 +1173,10 @@ PathManipulator::_SetTransformBox(TransformPointsBox* transformBox)
fTransformBox = transformBox;
// TODO: this is weird, fMode should only be set in _SetMode, not
// here as well, also this method could be called this way
// _SetModeForMousePos -> _SetMode -> _SetTransformBox
// and then below it does _SetModeForMousePos again...
if (fTransformBox) {
fTransformBox->MouseMoved(fLastCanvasPos);
if (fMode != TRANSFORM_POINTS) {

View File

@ -137,6 +137,8 @@ TransformBox::Draw(BView* into, BRect updateRect)
bool
TransformBox::MouseDown(BPoint where)
{
fView->FilterMouse(&where);
// NOTE: filter mouse here and in MouseMoved only
TransformToCanvas(where);
fDragging = true;
@ -155,6 +157,8 @@ TransformBox::MouseDown(BPoint where)
void
TransformBox::MouseMoved(BPoint where)
{
fView->FilterMouse(&where);
// NOTE: filter mouse here and in MouseDown only
TransformToCanvas(where);
if (fMousePos != where) {