* 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
+44 -25
View File
@@ -69,9 +69,18 @@ CanvasView::AttachedToWindow()
SetLowColor(kStripesHigh); SetLowColor(kStripesHigh);
SetHighColor(kStripesLow); 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 // FrameResized
@@ -79,6 +88,12 @@ void
CanvasView::FrameResized(float width, float height) CanvasView::FrameResized(float width, float height)
{ {
_AllocBackBitmap(width, height); _AllocBackBitmap(width, height);
// keep canvas centered
BPoint oldCanvasOrigin = fCanvasOrigin;
SetDataRect(_LayoutCanvas());
if (oldCanvasOrigin != fCanvasOrigin)
Invalidate();
} }
// Draw // Draw
@@ -515,34 +530,30 @@ CanvasView::_NextZoomOutLevel(double zoom) const
// _SetZoom // _SetZoom
void void
CanvasView::_SetZoom(double zoomLevel) CanvasView::_SetZoom(double zoomLevel, bool mouseIsAnchor)
{ {
if (fZoomLevel == zoomLevel) if (fZoomLevel == zoomLevel)
return; return;
// zoom into mouse position, or into center of view // TODO: still not working 100% correctly
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);
BPoint offset; // zoom into center of view
if (fZoomLevel < zoomLevel) { BRect bounds(Bounds());
offset.x = anchor.x * (zoomLevel / fZoomLevel) - anchor.x; BPoint anchor;
offset.y = anchor.y * (zoomLevel / fZoomLevel) - anchor.y; anchor.x = (bounds.left + bounds.right + 1) / 2.0;
} else { anchor.y = (bounds.top + bounds.bottom + 1) / 2.0;
offset.x = -anchor.x * (zoomLevel / fZoomLevel);
offset.y = -anchor.y * (zoomLevel / fZoomLevel); BPoint canvasAnchor = anchor;
} ConvertToCanvas(&canvasAnchor);
fZoomLevel = zoomLevel; fZoomLevel = zoomLevel;
SetDataRect(_LayoutCanvas()); 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); SetScrollOffset(ScrollOffset() + offset);
@@ -564,14 +575,22 @@ CanvasView::_LayoutCanvas()
// TODO: ask manipulators to extend size // TODO: ask manipulators to extend size
// left top of canvas within empty area BRect bitmapRect = r;
fCanvasOrigin.x = floorf(r.Width() * 0.25);
fCanvasOrigin.y = floorf(r.Height() * 0.25);
// resize for empty area around bitmap // 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.right += r.Width() * 0.5;
r.bottom += r.Height() * 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;
} }
+2 -1
View File
@@ -84,7 +84,8 @@ class CanvasView : public StateView,
private: private:
double _NextZoomInLevel(double zoom) const; double _NextZoomInLevel(double zoom) const;
double _NextZoomOutLevel(double zoom) const; double _NextZoomOutLevel(double zoom) const;
void _SetZoom(double zoomLevel); void _SetZoom(double zoomLevel,
bool mouseIsAnchor = true);
BRect _LayoutCanvas(); BRect _LayoutCanvas();
BBitmap* fBitmap; BBitmap* fBitmap;
+4 -5
View File
@@ -152,11 +152,10 @@ SavePanel::~SavePanel()
void void
SavePanel::SendMessage(const BMessenger* messenger, BMessage* message) SavePanel::SendMessage(const BMessenger* messenger, BMessage* message)
{ {
// add the current translator information to the message // add the current format information to the message,
if (message) { // bot only if we are indeed in export mode
int32 mode = ExportMode(); if (message && fFormatM->IsEnabled())
message->AddInt32("export mode", mode); message->AddInt32("export mode", ExportMode());
}
// let the original file panel code handle the rest // let the original file panel code handle the rest
BFilePanel::SendMessage(messenger, message); BFilePanel::SendMessage(messenger, message);
} }
@@ -50,7 +50,7 @@ RDefExporter::_Export(const uint8* source, size_t sourceSize, BPositionIO* strea
{ {
char buffer[2048]; char buffer[2048];
// write header // 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); size_t size = strlen(buffer);
ssize_t written = stream->Write(buffer, size); ssize_t written = stream->Write(buffer, size);