1 | /*
|
---|
2 | * Copyright 2019, Adrien Destugues <pulkomandy@pulkomandy.tk>
|
---|
3 | * Distributed under terms of the MIT license.
|
---|
4 | */
|
---|
5 |
|
---|
6 |
|
---|
7 | #include <Application.h>
|
---|
8 | #include <Bitmap.h>
|
---|
9 | #include <View.h>
|
---|
10 | #include <Window.h>
|
---|
11 |
|
---|
12 | #include <assert.h>
|
---|
13 |
|
---|
14 |
|
---|
15 | class BitmapView: public BView
|
---|
16 | {
|
---|
17 | public:
|
---|
18 | BitmapView(BBitmap* bitmap)
|
---|
19 | : BView(bitmap->Bounds(), "test view", B_FOLLOW_LEFT_TOP, B_WILL_DRAW)
|
---|
20 | , fBitmap(bitmap)
|
---|
21 | {
|
---|
22 | }
|
---|
23 |
|
---|
24 | ~BitmapView()
|
---|
25 | {
|
---|
26 | delete fBitmap;
|
---|
27 | }
|
---|
28 |
|
---|
29 | void Draw(BRect updateRect)
|
---|
30 | {
|
---|
31 | DrawBitmap(fBitmap);
|
---|
32 | }
|
---|
33 |
|
---|
34 | private:
|
---|
35 | BBitmap* fBitmap;
|
---|
36 | };
|
---|
37 |
|
---|
38 |
|
---|
39 | int
|
---|
40 | main(void)
|
---|
41 | {
|
---|
42 | BApplication app("application/Haiku-BitmapTest");
|
---|
43 |
|
---|
44 | BWindow* window = new BWindow(BRect(10, 10, 100, 100),
|
---|
45 | "Bitmap drawing test", B_DOCUMENT_WINDOW, B_QUIT_ON_WINDOW_CLOSE);
|
---|
46 | window->Show();
|
---|
47 |
|
---|
48 | BBitmap* bitmap = new BBitmap(BRect(0, 0, 24, 24), B_RGBA32, true);
|
---|
49 |
|
---|
50 | BView* childOfBitmap = new BView(bitmap->Bounds(), NULL, 0, B_WILL_DRAW);
|
---|
51 | bitmap->AddChild(childOfBitmap);
|
---|
52 | if (childOfBitmap->LockLooper()) {
|
---|
53 | //Uncomment to make FillRect fail
|
---|
54 | //childOfBitmap->Invalidate();
|
---|
55 | childOfBitmap->SetHighColor(0, 0, 0, 128);
|
---|
56 | childOfBitmap->FillRect(childOfBitmap->Bounds());
|
---|
57 | childOfBitmap->Invalidate();
|
---|
58 | childOfBitmap->UnlockLooper();
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | BView* view = new BitmapView(bitmap);
|
---|
63 | window->AddChild(view);
|
---|
64 |
|
---|
65 | app.Run();
|
---|
66 | return 0;
|
---|
67 | }
|
---|