1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: Bitmap.h 23 // Author: Ingo Weinhold (bonefish@users.sf.net) 24 // Description: BBitmap objects represent off-screen windows that 25 // contain bitmap data. 26 //------------------------------------------------------------------------------ 27 28 #ifndef _BITMAP_H 29 #define _BITMAP_H 30 31 #include <Archivable.h> 32 #include <InterfaceDefs.h> 33 #include <Rect.h> 34 35 class BWindow; 36 37 enum { 38 B_BITMAP_CLEAR_TO_WHITE = 0x00000001, 39 B_BITMAP_ACCEPTS_VIEWS = 0x00000002, 40 B_BITMAP_IS_AREA = 0x00000004, 41 B_BITMAP_IS_LOCKED = 0x00000008 | B_BITMAP_IS_AREA, 42 B_BITMAP_IS_CONTIGUOUS = 0x00000010 | B_BITMAP_IS_LOCKED, 43 B_BITMAP_IS_OFFSCREEN = 0x00000020, 44 B_BITMAP_WILL_OVERLAY = 0x00000040 | B_BITMAP_IS_OFFSCREEN, 45 B_BITMAP_RESERVE_OVERLAY_CHANNEL = 0x00000080 46 }; 47 48 #define B_ANY_BYTES_PER_ROW -1 49 50 //----------------------------------------------------------------// 51 //----- BBitmap class --------------------------------------------// 52 53 class BBitmap : public BArchivable { 54 public: 55 BBitmap(BRect bounds, uint32 flags, color_space colorSpace, 56 int32 bytesPerRow = B_ANY_BYTES_PER_ROW, 57 screen_id screenID = B_MAIN_SCREEN_ID); 58 BBitmap(BRect bounds, color_space colorSpace, bool acceptsViews = false, 59 bool needsContiguous = false); 60 BBitmap(const BBitmap *source, bool acceptsViews = false, 61 bool needsContiguous = false); 62 virtual ~BBitmap(); 63 64 // Archiving 65 BBitmap(BMessage *data); 66 static BArchivable *Instantiate(BMessage *data); 67 virtual status_t Archive(BMessage *data, bool deep = true) const; 68 69 status_t InitCheck() const; 70 bool IsValid() const; 71 72 status_t LockBits(uint32 *state = NULL); 73 void UnlockBits(); 74 75 area_id Area() const; 76 void *Bits() const; 77 int32 BitsLength() const; 78 int32 BytesPerRow() const; 79 color_space ColorSpace() const; 80 BRect Bounds() const; 81 82 void SetBits(const void *data, int32 length, int32 offset, 83 color_space colorSpace); 84 85 // not part of the R5 API 86 status_t ImportBits(const void *data, int32 length, int32 bpr, 87 int32 offset, color_space colorSpace); 88 status_t ImportBits(const BBitmap *bitmap); 89 90 status_t GetOverlayRestrictions(overlay_restrictions *restrictions) const; 91 92 // to mimic a BWindow 93 virtual void AddChild(BView *view); 94 virtual bool RemoveChild(BView *view); 95 int32 CountChildren() const; 96 BView *ChildAt(int32 index) const; 97 BView *FindView(const char *viewName) const; 98 BView *FindView(BPoint point) const; 99 bool Lock(); 100 void Unlock(); 101 bool IsLocked() const; 102 103 //----- Private or reserved -----------------------------------------// 104 105 virtual status_t Perform(perform_code d, void *arg); 106 107 private: 108 friend class BView; 109 friend class BApplication; 110 friend void _get_screen_bitmap_(BBitmap *, BRect, bool); 111 112 virtual void _ReservedBitmap1(); 113 virtual void _ReservedBitmap2(); 114 virtual void _ReservedBitmap3(); 115 116 BBitmap(const BBitmap &); 117 BBitmap &operator=(const BBitmap &); 118 119 char *get_shared_pointer() const; 120 int32 get_server_token() const; 121 void InitObject(BRect bounds, color_space colorSpace, uint32 flags, 122 int32 bytesPerRow, screen_id screenID); 123 void AssertPtr(); 124 125 void *fBasePtr; 126 int32 fSize; 127 color_space fColorSpace; 128 BRect fBounds; 129 int32 fBytesPerRow; 130 BWindow *fWindow; 131 int32 fServerToken; 132 int32 fToken; 133 uint8 unused; 134 area_id fArea; 135 area_id fOrigArea; 136 uint32 fFlags; 137 status_t fInitError; 138 }; 139 140 /*-------------------------------------------------------------*/ 141 /*-------------------------------------------------------------*/ 142 143 #endif // _BITMAP_H 144