1 /* 2 * Copyright (c) 2023 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 OHOS_ROSEN_SESSION_HELPER_H 17 #define OHOS_ROSEN_SESSION_HELPER_H 18 19 #include <string> 20 #include "ws_common.h" 21 #include "wm_common.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 class SessionHelper { 26 public: GetOverlap(const WSRect & rect1,const WSRect & rect2,int offsetX,int offsetY)27 static WSRect GetOverlap(const WSRect& rect1, const WSRect& rect2, int offsetX, int offsetY) 28 { 29 int32_t x_begin = std::max(rect1.posX_, rect2.posX_); 30 int32_t x_end = std::min(rect1.posX_ + static_cast<int32_t>(rect1.width_), 31 rect2.posX_ + static_cast<int32_t>(rect2.width_)); 32 int32_t y_begin = std::max(rect1.posY_, rect2.posY_); 33 int32_t y_end = std::min(rect1.posY_ + static_cast<int32_t>(rect1.height_), 34 rect2.posY_ + static_cast<int32_t>(rect2.height_)); 35 if (y_begin >= y_end || x_begin >= x_end) { 36 return { 0, 0, 0, 0 }; 37 } 38 return { x_begin - offsetX, y_begin - offsetY, 39 static_cast<uint32_t>(x_end - x_begin), static_cast<uint32_t>(y_end - y_begin) }; 40 } 41 IsEmptyRect(const WSRect & r)42 static inline bool IsEmptyRect(const WSRect& r) 43 { 44 return (r.posX_ == 0 && r.posY_ == 0 && r.width_ == 0 && r.height_ == 0); 45 } 46 IsPointInRect(int32_t pointPosX,int32_t pointPosY,const Rect & rect)47 static bool IsPointInRect(int32_t pointPosX, int32_t pointPosY, const Rect& rect) 48 { 49 if ((pointPosX > rect.posX_) && 50 (pointPosX < (rect.posX_ + static_cast<int32_t>(rect.width_)) - 1) && 51 (pointPosY > rect.posY_) && 52 (pointPosY < (rect.posY_ + static_cast<int32_t>(rect.height_)) - 1)) { 53 return true; 54 } 55 return false; 56 } 57 TransferToWSRect(const Rect & rect)58 static inline WSRect TransferToWSRect(const Rect& rect) 59 { 60 WSRect r; 61 r.height_ = rect.height_; 62 r.width_ = rect.width_; 63 r.posX_ = rect.posX_; 64 r.posY_ = rect.posY_; 65 return r; 66 } 67 TransferToRect(const WSRect & rect)68 static inline Rect TransferToRect(const WSRect& rect) 69 { 70 Rect r; 71 r.height_ = rect.height_; 72 r.width_ = rect.width_; 73 r.posX_ = rect.posX_; 74 r.posY_ = rect.posY_; 75 return r; 76 } 77 }; 78 } // Rosen 79 } // OHOS 80 #endif // OHOS_ROSEN_SESSION_HELPER_H