2 * Copyright (c) 2007, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
6 * Ćukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
10 #include "PackageImageViewer.h"
12 #include <BitmapStream.h>
17 #include <TranslatorRoster.h>
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "PackageImageViewer"
24 ImageView::ImageView(BPositionIO
* imageIO
)
26 BView(BRect(0, 0, 1, 1), "image_view", B_FOLLOW_NONE
, B_WILL_DRAW
),
32 // Initialize and translate the image
33 BTranslatorRoster
* roster
= BTranslatorRoster::Default();
35 if (roster
->Translate(imageIO
, NULL
, NULL
, &stream
, B_TRANSLATOR_BITMAP
)
39 stream
.DetachBitmap(&fImage
);
43 ImageView::~ImageView()
50 ImageView::AttachedToWindow()
57 // We need to resize the view depending on what size has the screen and
58 // the image we will be viewing
59 BScreen
screen(Window());
60 BRect frame
= screen
.Frame();
61 BRect image
= fImage
->Bounds();
63 if (image
.Width() > (frame
.Width() - 100.0f
))
64 image
.right
= frame
.Width() - 100.0f
;
65 if (image
.Height() > (frame
.Height() - 100.0f
))
66 image
.bottom
= frame
.Height() - 100.f
;
68 ResizeTo(image
.Width(), image
.Height());
73 ImageView::Draw(BRect updateRect
)
76 DrawBitmapAsync(fImage
, Bounds());
78 const char* message
= B_TRANSLATE("Image not loaded correctly");
79 float width
= StringWidth(message
);
80 DrawString(message
, BPoint((Bounds().Width() - width
) / 2.0f
, 30.0f
));
86 ImageView::MouseUp(BPoint point
)
88 BWindow
* window
= Window();
90 window
->PostMessage(B_QUIT_REQUESTED
);
97 PackageImageViewer::PackageImageViewer(BPositionIO
* imageIO
)
99 BlockingWindow(BRect(100, 100, 100, 100), "")
101 fBackground
= new ImageView(imageIO
);
102 AddChild(fBackground
);
104 ResizeTo(fBackground
->Bounds().Width(), fBackground
->Bounds().Height());
106 BScreen
screen(this);
107 BRect frame
= screen
.Frame();
108 MoveTo((frame
.Width() - Bounds().Width()) / 2.0f
,
109 (frame
.Height() - Bounds().Height()) / 2.0f
);