1 /* 2 * Copyright 2001-2007, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold (bonefish@users.sf.net) 7 */ 8 #ifndef _BITMAP_H 9 #define _BITMAP_H 10 11 12 #include <Archivable.h> 13 #include <InterfaceDefs.h> 14 #include <Rect.h> 15 16 class BView; 17 class BWindow; 18 namespace BPrivate { 19 class BPrivateScreen; 20 } 21 22 enum { 23 B_BITMAP_CLEAR_TO_WHITE = 0x00000001, 24 B_BITMAP_ACCEPTS_VIEWS = 0x00000002, 25 B_BITMAP_IS_AREA = 0x00000004, 26 B_BITMAP_IS_LOCKED = 0x00000008 | B_BITMAP_IS_AREA, 27 B_BITMAP_IS_CONTIGUOUS = 0x00000010 | B_BITMAP_IS_LOCKED, 28 B_BITMAP_IS_OFFSCREEN = 0x00000020, 29 B_BITMAP_WILL_OVERLAY = 0x00000040 | B_BITMAP_IS_OFFSCREEN, 30 B_BITMAP_RESERVE_OVERLAY_CHANNEL = 0x00000080, 31 B_BITMAP_NO_SERVER_LINK = 0x00000100 32 }; 33 34 #define B_ANY_BYTES_PER_ROW -1 35 36 37 class BBitmap : public BArchivable { 38 public: 39 BBitmap(BRect bounds, uint32 flags, color_space colorSpace, 40 int32 bytesPerRow = B_ANY_BYTES_PER_ROW, 41 screen_id screenID = B_MAIN_SCREEN_ID); 42 BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews = false, 43 bool needsContiguous = false); 44 BBitmap(const BBitmap& source, uint32 flags); 45 BBitmap(const BBitmap& source); 46 BBitmap(const BBitmap *source, bool acceptsViews = false, 47 bool needsContiguous = false); 48 virtual ~BBitmap(); 49 50 // Archiving 51 BBitmap(BMessage *data); 52 static BArchivable *Instantiate(BMessage *data); 53 virtual status_t Archive(BMessage *data, bool deep = true) const; 54 55 status_t InitCheck() const; 56 bool IsValid() const; 57 58 status_t LockBits(uint32 *state = NULL); 59 void UnlockBits(); 60 61 area_id Area() const; 62 void *Bits() const; 63 int32 BitsLength() const; 64 int32 BytesPerRow() const; 65 color_space ColorSpace() const; 66 BRect Bounds() const; 67 uint32 Flags() const; 68 69 void SetBits(const void *data, int32 length, int32 offset, 70 color_space colorSpace); 71 72 // not part of the R5 API 73 status_t ImportBits(const void *data, int32 length, int32 bpr, 74 int32 offset, color_space colorSpace); 75 status_t ImportBits(const void *data, int32 length, int32 bpr, 76 color_space colorSpace, BPoint from, BPoint to, 77 int32 width, int32 height); 78 status_t ImportBits(const BBitmap *bitmap); 79 status_t ImportBits(const BBitmap *bitmap, BPoint from, BPoint to, 80 int32 width, int32 height); 81 82 status_t GetOverlayRestrictions(overlay_restrictions *restrictions) const; 83 84 // to mimic a BWindow 85 virtual void AddChild(BView *view); 86 virtual bool RemoveChild(BView *view); 87 int32 CountChildren() const; 88 BView *ChildAt(int32 index) const; 89 BView *FindView(const char *viewName) const; 90 BView *FindView(BPoint point) const; 91 bool Lock(); 92 void Unlock(); 93 bool IsLocked() const; 94 95 BBitmap& operator=(const BBitmap& source); 96 97 private: 98 friend class BView; 99 friend class BApplication; 100 friend class BPrivate::BPrivateScreen; 101 102 virtual status_t Perform(perform_code d, void *arg); 103 virtual void _ReservedBitmap1(); 104 virtual void _ReservedBitmap2(); 105 virtual void _ReservedBitmap3(); 106 107 int32 _ServerToken() const; 108 void _InitObject(BRect bounds, color_space colorSpace, uint32 flags, 109 int32 bytesPerRow, screen_id screenID); 110 void _CleanUp(); 111 void _AssertPointer(); 112 113 uint8 *fBasePointer; 114 int32 fSize; 115 color_space fColorSpace; 116 BRect fBounds; 117 int32 fBytesPerRow; 118 BWindow *fWindow; 119 int32 fServerToken; 120 int32 fAreaOffset; 121 uint8 unused; 122 area_id fArea; 123 area_id fServerArea; 124 uint32 fFlags; 125 status_t fInitError; 126 }; 127 128 #endif // _BITMAP_H 129