1 /* 2 * Copyright 2001-2006, 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 BPrivateScreen; 17 class BWindow; 18 19 enum { 20 B_BITMAP_CLEAR_TO_WHITE = 0x00000001, 21 B_BITMAP_ACCEPTS_VIEWS = 0x00000002, 22 B_BITMAP_IS_AREA = 0x00000004, 23 B_BITMAP_IS_LOCKED = 0x00000008 | B_BITMAP_IS_AREA, 24 B_BITMAP_IS_CONTIGUOUS = 0x00000010 | B_BITMAP_IS_LOCKED, 25 B_BITMAP_IS_OFFSCREEN = 0x00000020, 26 B_BITMAP_WILL_OVERLAY = 0x00000040 | B_BITMAP_IS_OFFSCREEN, 27 B_BITMAP_RESERVE_OVERLAY_CHANNEL = 0x00000080, 28 B_BITMAP_NO_SERVER_LINK = 0x00000100 29 }; 30 31 #define B_ANY_BYTES_PER_ROW -1 32 33 34 class BBitmap : public BArchivable { 35 public: 36 BBitmap(BRect bounds, uint32 flags, color_space colorSpace, 37 int32 bytesPerRow = B_ANY_BYTES_PER_ROW, 38 screen_id screenID = B_MAIN_SCREEN_ID); 39 BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews = false, 40 bool needsContiguous = false); 41 BBitmap(const BBitmap& source, uint32 flags); 42 BBitmap(const BBitmap& source); 43 BBitmap(const BBitmap *source, bool acceptsViews = false, 44 bool needsContiguous = false); 45 virtual ~BBitmap(); 46 47 // Archiving 48 BBitmap(BMessage *data); 49 static BArchivable *Instantiate(BMessage *data); 50 virtual status_t Archive(BMessage *data, bool deep = true) const; 51 52 status_t InitCheck() const; 53 bool IsValid() const; 54 55 status_t LockBits(uint32 *state = NULL); 56 void UnlockBits(); 57 58 area_id Area() const; 59 void *Bits() const; 60 int32 BitsLength() const; 61 int32 BytesPerRow() const; 62 color_space ColorSpace() const; 63 BRect Bounds() const; 64 uint32 Flags() const; 65 66 void SetBits(const void *data, int32 length, int32 offset, 67 color_space colorSpace); 68 69 // not part of the R5 API 70 status_t ImportBits(const void *data, int32 length, int32 bpr, 71 int32 offset, color_space colorSpace); 72 status_t ImportBits(const void *data, int32 length, int32 bpr, 73 color_space colorSpace, BPoint from, BPoint to, 74 int32 width, int32 height); 75 status_t ImportBits(const BBitmap *bitmap); 76 status_t ImportBits(const BBitmap *bitmap, BPoint from, BPoint to, 77 int32 width, int32 height); 78 79 status_t GetOverlayRestrictions(overlay_restrictions *restrictions) const; 80 81 // to mimic a BWindow 82 virtual void AddChild(BView *view); 83 virtual bool RemoveChild(BView *view); 84 int32 CountChildren() const; 85 BView *ChildAt(int32 index) const; 86 BView *FindView(const char *viewName) const; 87 BView *FindView(BPoint point) const; 88 bool Lock(); 89 void Unlock(); 90 bool IsLocked() const; 91 92 BBitmap& operator=(const BBitmap& source); 93 94 //----- Private or reserved -----------------------------------------// 95 96 virtual status_t Perform(perform_code d, void *arg); 97 98 private: 99 friend class BView; 100 friend class BApplication; 101 friend class BPrivateScreen; 102 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