#include <stdio.h>
#include <Application.h>
#include <Bitmap.h>
#include <View.h>
#include <Window.h>
class TestView : public BView {
public:
TestView(BRect frame, const char* name,
uint32 resizeFlags, uint32 flags);
virtual void Draw(BRect updateRect);
private:
BBitmap* fBitmap;
};
#define LEFT_OFFSET 30
#define TOP_OFFSET 30
TestView::TestView(BRect frame, const char* name,
uint32 resizeFlags, uint32 flags)
: BView(frame, name, resizeFlags, flags),
fBitmap(new BBitmap(BRect(0 + LEFT_OFFSET,
0 + TOP_OFFSET,
99 + LEFT_OFFSET,
99 + TOP_OFFSET),
B_BITMAP_CLEAR_TO_WHITE,
B_RGB32))
{
SetViewColor(216, 216, 216);
uint8* bits = (uint8*)fBitmap->Bits();
uint32 width = fBitmap->Bounds().IntegerWidth() + 1;
uint32 height = fBitmap->Bounds().IntegerHeight() + 1;
uint32 bpr = fBitmap->BytesPerRow();
uint8* b = bits;
for (uint32 x = 0; x < width; x++) {
b[0] = 0;
b[1] = 0;
b += 4;
}
b = bits + bpr;
for (uint32 y = 1; y < height - 1; y++) {
b[0] = 0;
b[1] = 0;
b[(width - 1) * 4 + 0] = 0;
b[(width - 1) * 4 + 1] = 0;
b += bpr;
}
for (uint32 x = 0; x < width; x++) {
b[0] = 0;
b[1] = 0;
b += 4;
}
}
void
TestView::Draw(BRect updateRect)
{
BRect bitmap = fBitmap->Bounds();
BRect view = bitmap.OffsetToCopy(B_ORIGIN);
DrawBitmap(fBitmap, bitmap, view);
}
int
main(int argc, char** argv)
{
BApplication app("application/x.vnd-Haiku.BitmapBounds");
BRect frame(50.0, 50.0, 300.0, 250.0);
BWindow* window = new BWindow(frame, "Bitmap Bounds", B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
BView* view = new TestView(window->Bounds(), "test",
B_FOLLOW_ALL, B_WILL_DRAW);
window->AddChild(view);
window->Show();
app.Run();
return 0;
}