The Android Open Source Project | 52d4c30 | 2009-03-03 19:29:09 -0800 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2005 The Android Open Source Project |
| 3 | // |
| 4 | // Simulated device definition. |
| 5 | // |
| 6 | #ifndef _SIM_LOADABLE_IMAGE_H |
| 7 | #define _SIM_LOADABLE_IMAGE_H |
| 8 | |
| 9 | #include "utils.h" |
| 10 | |
| 11 | /* |
| 12 | * Holds an image that may or may not be loaded at present. The image |
| 13 | * has an (x,y) offset. |
| 14 | */ |
| 15 | class LoadableImage { |
| 16 | public: |
| 17 | LoadableImage(void) |
| 18 | : mName(NULL), mpBitmap(NULL), mX(-1), mY(-1), mWidth(-1), mHeight(-1) |
| 19 | {} |
| 20 | virtual ~LoadableImage(void) { |
| 21 | delete[] mName; |
| 22 | delete mpBitmap; |
| 23 | } |
| 24 | LoadableImage(const LoadableImage& src) |
| 25 | : mName(NULL), mpBitmap(NULL) |
| 26 | { |
| 27 | CopyMembers(src); |
| 28 | } |
| 29 | LoadableImage& operator=(const LoadableImage& src) { |
| 30 | if (this != &src) // self-assignment |
| 31 | CopyMembers(src); |
| 32 | return *this; |
| 33 | } |
| 34 | void CopyMembers(const LoadableImage& src) { |
| 35 | // Need to delete resources in case we're using operator= and |
| 36 | // assigning into an object that already holds some. |
| 37 | delete mName; |
| 38 | delete mpBitmap; |
| 39 | mName = android::strdupNew(src.mName); |
| 40 | if (src.mpBitmap == NULL) |
| 41 | mpBitmap = NULL; |
| 42 | else |
| 43 | mpBitmap = new wxBitmap(*(src.mpBitmap)); |
| 44 | mX = src.mX; |
| 45 | mY = src.mY; |
| 46 | mWidth = src.mWidth; |
| 47 | mHeight = src.mHeight; |
| 48 | } |
| 49 | |
| 50 | virtual bool Create(const char* fileName, int x, int y); |
| 51 | |
| 52 | // load or unload the bitmap |
| 53 | bool LoadResources(void); |
| 54 | bool UnloadResources(void); |
| 55 | |
| 56 | // accessors |
| 57 | int GetX(void) const { return mX; } |
| 58 | int GetY(void) const { return mY; } |
| 59 | int GetWidth(void) const { return mWidth; } |
| 60 | int GetHeight(void) const { return mHeight; } |
| 61 | wxBitmap* GetBitmap(void) const { return mpBitmap; } |
| 62 | |
| 63 | private: |
| 64 | char* mName; |
| 65 | wxBitmap* mpBitmap; |
| 66 | |
| 67 | int mX; // position relative to phone image |
| 68 | int mY; |
| 69 | int mWidth; // from image (cached values) |
| 70 | int mHeight; |
| 71 | }; |
| 72 | |
| 73 | #endif // _SIM_LOADABLE_IMAGE_H |