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 | // Phone button image holder. |
| 5 | // |
| 6 | #ifndef _SIM_PHONE_BUTTON_H |
| 7 | #define _SIM_PHONE_BUTTON_H |
| 8 | |
| 9 | #include "LoadableImage.h" |
| 10 | #include <ui/KeycodeLabels.h> |
| 11 | |
| 12 | /* |
| 13 | * One button on a phone. Position, size, and a highlight graphic. The |
| 14 | * coordinates are relative to the device graphic. |
| 15 | * |
| 16 | * We now have a "highlighted" graphic for mouse-overs and a "selected" |
| 17 | * graphic for button presses. We assume they have the same dimensions. |
| 18 | * We currently assume that either both or neither exist, because we |
| 19 | * generate one from the other. |
| 20 | */ |
| 21 | class PhoneButton { |
| 22 | public: |
| 23 | PhoneButton(void) |
| 24 | : mHasImage(false), mKeyCode(kKeyCodeUnknown) |
| 25 | {} |
| 26 | virtual ~PhoneButton(void) {} |
| 27 | PhoneButton(const PhoneButton& src) |
| 28 | : mHasImage(false), mKeyCode(kKeyCodeUnknown) |
| 29 | { |
| 30 | CopyMembers(src); |
| 31 | } |
| 32 | PhoneButton& operator=(const PhoneButton& src) { |
| 33 | if (this != &src) { |
| 34 | // Unload any resources in case we're using operator= to |
| 35 | // assign to an existing object. |
| 36 | mSelectedImage.UnloadResources(); |
| 37 | // Copy fields. |
| 38 | CopyMembers(src); |
| 39 | } |
| 40 | return *this; |
| 41 | } |
| 42 | void CopyMembers(const PhoneButton& src) { |
| 43 | mSelectedImage = src.mSelectedImage; |
| 44 | mHighlightedBitmap = src.mHighlightedBitmap; |
| 45 | mHasImage = src.mHasImage; |
| 46 | mKeyCode = src.mKeyCode; |
| 47 | } |
| 48 | |
| 49 | /* finish construction of PhoneButton, with or without an image */ |
| 50 | bool Create(const char* label); |
| 51 | bool Create(const char* label, const char* imageFileName, int x, int y); |
| 52 | |
| 53 | int GetX(void) const { return mSelectedImage.GetX(); } |
| 54 | int GetY(void) const { return mSelectedImage.GetY(); } |
| 55 | int GetWidth(void) const { return mSelectedImage.GetWidth(); } |
| 56 | int GetHeight(void) const { return mSelectedImage.GetHeight(); } |
| 57 | wxBitmap* GetHighlightedBitmap(void) { return &mHighlightedBitmap; } |
| 58 | wxBitmap* GetSelectedBitmap(void) const { |
| 59 | return mSelectedImage.GetBitmap(); |
| 60 | } |
| 61 | |
| 62 | bool CheckCollision(int x, int y) const; |
| 63 | KeyCode GetKeyCode(void) const { return mKeyCode; } |
| 64 | |
| 65 | // load or unload the image bitmap, if any |
| 66 | bool LoadResources(void); |
| 67 | bool UnloadResources(void); |
| 68 | |
| 69 | private: |
| 70 | void CreateHighlightedBitmap(void); |
| 71 | KeyCode LookupKeyCode(const char* label) const; |
| 72 | |
| 73 | LoadableImage mSelectedImage; |
| 74 | wxBitmap mHighlightedBitmap; |
| 75 | bool mHasImage; // both exist or neither exist |
| 76 | |
| 77 | KeyCode mKeyCode; |
| 78 | }; |
| 79 | |
| 80 | #endif // _SIM_PHONE_BUTTON_H |