1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CHARGER_UI_VIEW_H 17 #define CHARGER_UI_VIEW_H 18 19 #include <mutex> 20 21 namespace OHOS { 22 namespace HDI { 23 namespace Battery { 24 namespace V1_0 { 25 class View { 26 public: 27 struct BRGA888Pixel { 28 unsigned char r; 29 unsigned char g; 30 unsigned char b; 31 unsigned char a; 32 }; 33 34 struct RGB888Pixel { 35 unsigned char r; 36 unsigned char g; 37 unsigned char b; 38 }; 39 40 enum class PixelFormat { 41 BGRA888, 42 }; View()43 View() {}; ~View()44 virtual ~View() {}; 45 void* CreateBuffer(int w, int h, View::PixelFormat pixelFormat); 46 virtual void SetBackgroundColor(BRGA888Pixel* color); 47 virtual void DrawSubView(int x, int y, int w, int h, char* buf); 48 virtual void OnDraw(); 49 virtual void Hide(); 50 virtual void Show(); 51 virtual void OnFocus(bool foucsed); 52 char* GetBuffer() const; 53 void* GetRawBuffer() const; GetBufferSize()54 int GetBufferSize() const 55 { 56 return bufferSize_; 57 } 58 void SyncBuffer(); 59 void SetViewId(int id); 60 int GetViewId() const; 61 void FreeBuffer(); 62 bool IsVisiable() const; 63 bool IsSelected() const; 64 bool IsFocusAble() const; 65 void SetFocusAble(bool focusable); 66 int startX_ = 0; 67 int startY_ = 0; 68 int viewWidth_ = 0; 69 int viewHeight_ = 0; 70 std::mutex mutex_; 71 private: 72 char* viewBuffer_ = nullptr; 73 char* shadowBuffer_ = nullptr; 74 int bufferSize_ = 0; 75 bool isVisiable_ = true; 76 int viewId_ = 0; 77 bool focusable_ = false; 78 bool isFocused_ = false; 79 }; 80 } // namespace V1_0 81 } // namespace Battery 82 } // namespace HDI 83 } // namespace OHOS 84 #endif // CHARGER_UI_VIEW_H 85