* fixed stupid bug that prevented saving in native format

* fixed bug in RDefExporter
* improved zooming, icon is now centered at program start


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19328 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2006-11-19 10:13:23 +00:00
parent c9ed0088c9
commit fae6fb6d69
4 changed files with 51 additions and 32 deletions

View File

@ -69,9 +69,18 @@ CanvasView::AttachedToWindow()
SetLowColor(kStripesHigh);
SetHighColor(kStripesLow);
_AllocBackBitmap(Bounds().Width(), Bounds().Height());
BRect bounds(Bounds());
_SetZoom(8.0);
_AllocBackBitmap(bounds.Width(), bounds.Height());
// layout icon in the center
BRect bitmapBounds(fBitmap->Bounds());
fCanvasOrigin.x = floorf((bounds.left + bounds.right
- bitmapBounds.right - bitmapBounds.left) / 2.0 + 0.5);
fCanvasOrigin.y = floorf((bounds.top + bounds.bottom
- bitmapBounds.bottom - bitmapBounds.top) / 2.0 + 0.5);
_SetZoom(8.0, false);
}
// FrameResized
@ -79,6 +88,12 @@ void
CanvasView::FrameResized(float width, float height)
{
_AllocBackBitmap(width, height);
// keep canvas centered
BPoint oldCanvasOrigin = fCanvasOrigin;
SetDataRect(_LayoutCanvas());
if (oldCanvasOrigin != fCanvasOrigin)
Invalidate();
}
// Draw
@ -515,34 +530,30 @@ CanvasView::_NextZoomOutLevel(double zoom) const
// _SetZoom
void
CanvasView::_SetZoom(double zoomLevel)
CanvasView::_SetZoom(double zoomLevel, bool mouseIsAnchor)
{
if (fZoomLevel == zoomLevel)
return;
// zoom into mouse position, or into center of view
BPoint anchor = MouseInfo()->position;
BRect bounds(Bounds());
if (!bounds.Contains(anchor)) {
bounds = _CanvasRect();
anchor.x = (bounds.left + bounds.right) / 2.0;
anchor.y = (bounds.top + bounds.bottom) / 2.0;
}
printf("anchor: %.2f, %.2f\n", anchor.x, anchor.y);
// TODO: still not working 100% correctly
BPoint offset;
if (fZoomLevel < zoomLevel) {
offset.x = anchor.x * (zoomLevel / fZoomLevel) - anchor.x;
offset.y = anchor.y * (zoomLevel / fZoomLevel) - anchor.y;
} else {
offset.x = -anchor.x * (zoomLevel / fZoomLevel);
offset.y = -anchor.y * (zoomLevel / fZoomLevel);
}
// zoom into center of view
BRect bounds(Bounds());
BPoint anchor;
anchor.x = (bounds.left + bounds.right + 1) / 2.0;
anchor.y = (bounds.top + bounds.bottom + 1) / 2.0;
BPoint canvasAnchor = anchor;
ConvertToCanvas(&canvasAnchor);
fZoomLevel = zoomLevel;
SetDataRect(_LayoutCanvas());
printf("offset: %.2f, %.2f\n", offset.x, offset.y);
ConvertFromCanvas(&canvasAnchor);
BPoint offset;
offset.x = roundf(canvasAnchor.x - anchor.x);
offset.y = roundf(canvasAnchor.y - anchor.y);
SetScrollOffset(ScrollOffset() + offset);
@ -564,14 +575,22 @@ CanvasView::_LayoutCanvas()
// TODO: ask manipulators to extend size
// left top of canvas within empty area
fCanvasOrigin.x = floorf(r.Width() * 0.25);
fCanvasOrigin.y = floorf(r.Height() * 0.25);
BRect bitmapRect = r;
// resize for empty area around bitmap
// (the size we want, but might still be much smaller than view)
r.right += r.Width() * 0.5;
r.bottom += r.Height() * 0.5;
return r;
// left top of canvas within empty area
BRect bounds(Bounds());
bounds.OffsetTo(B_ORIGIN);
bounds = bounds | r;
fCanvasOrigin.x = floorf((bounds.left + bounds.right
- bitmapRect.right - bitmapRect.left) / 2.0 + 0.5);
fCanvasOrigin.y = floorf((bounds.top + bounds.bottom
- bitmapRect.bottom - bitmapRect.top) / 2.0 + 0.5);
return bounds;
}

View File

@ -84,7 +84,8 @@ class CanvasView : public StateView,
private:
double _NextZoomInLevel(double zoom) const;
double _NextZoomOutLevel(double zoom) const;
void _SetZoom(double zoomLevel);
void _SetZoom(double zoomLevel,
bool mouseIsAnchor = true);
BRect _LayoutCanvas();
BBitmap* fBitmap;

View File

@ -152,11 +152,10 @@ SavePanel::~SavePanel()
void
SavePanel::SendMessage(const BMessenger* messenger, BMessage* message)
{
// add the current translator information to the message
if (message) {
int32 mode = ExportMode();
message->AddInt32("export mode", mode);
}
// add the current format information to the message,
// bot only if we are indeed in export mode
if (message && fFormatM->IsEnabled())
message->AddInt32("export mode", ExportMode());
// let the original file panel code handle the rest
BFilePanel::SendMessage(messenger, message);
}

View File

@ -50,7 +50,7 @@ RDefExporter::_Export(const uint8* source, size_t sourceSize, BPositionIO* strea
{
char buffer[2048];
// write header
sprintf(buffer, "\nresource(<your resource id here>) #'RAWT' array {\n");
sprintf(buffer, "\nresource(<your resource id here>) #'VICN' array {\n");
size_t size = strlen(buffer);
ssize_t written = stream->Write(buffer, size);