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_GRAY1); 49 50 // Bitmap is 25 pixels wide, which rounds up to 4 pixels 51 // The last byte only has one bit used, and 7 bits of padding 52 assert(bitmap->BytesPerRow() == 4); 53 54 // This was extracted from letter_a.pbm and should look mostly like a 55 // black "A" letter on a white background (confirmed BeOS behavior) 56 const unsigned char data[] = { 57 0, 0, 0, 0, 58 0, 8, 0, 0, 59 0, 0x1c, 0, 0, 60 0, 0x3e, 0, 0, 61 0, 0x7e, 0, 0, 62 0, 0xFF, 0, 0, 63 0, 0xE7, 0, 0, 64 0, 0xC3, 0, 0, 65 1, 0xC3, 0x80, 0, 66 1, 0x81, 0x80, 0, 67 3, 0x81, 0xC0, 0, 68 3, 0xFF, 0xC0, 0, 69 7, 0xFF, 0xE0, 0, 70 7, 0xFF, 0xE0, 0, 71 7, 0x81, 0xE0, 0, 72 0x0F, 0, 0x0F, 0, 73 0x0F, 0, 0x0F, 0, 74 0x1F, 0, 0xF8, 0, 75 0x1E, 0, 0x78, 0, 76 0x1C, 0, 0x38, 0, 77 0x3C, 0, 0x3C, 0, 78 0x3C, 0, 0x3C, 0, 79 0x38, 0, 0x0E, 0, 80 0x78, 0, 0x0F, 0, 81 0, 0, 0, 0 82 }; 83 bitmap->SetBits(data, sizeof(data), 0, B_GRAY1); 84 85 BView* view = new BitmapView(bitmap); 86 window->AddChild(view); 87 88 app.Run(); 89 return 0; 90 } 91