diff --git a/previewer/BUILD.gn b/previewer/BUILD.gn index ef2e21fedb91f1585090266f1e7627196253e18a..665fe852370b051c6f50ad70ddcf540ff0c94f70 100644 --- a/previewer/BUILD.gn +++ b/previewer/BUILD.gn @@ -41,6 +41,7 @@ ohos_shared_library("previewer_window") { "src/window.cpp", "src/window_impl.cpp", "src/window_scene.cpp", + "src/window_model.cpp" ] include_dirs = [ diff --git a/previewer/include/window_model.h b/previewer/include/window_model.h new file mode 100644 index 0000000000000000000000000000000000000000..ce2adc91a67ec08ad45d7244bdc42147de23efe4 --- /dev/null +++ b/previewer/include/window_model.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_INNERKITS_WINDOW_MODEL_H +#define INTERFACES_INNERKITS_WINDOW_MODEL_H + +#include "window_impl.h" + +namespace OHOS { +namespace Previewer { +enum class Orientation : int32_t { + PORTRAIT, + LANDSCAPE, + ORIENTATION_UNDEFINED, +}; + +enum class DeviceType { + PHONE, + TV, + WATCH, + CAR, + TABLET, + UNKNOWN, +}; + +enum class ColorMode : int32_t { + LIGHT = 0, + DARK, + COLOR_MODE_UNDEFINED, +}; + +struct PreviewerWindowModel { + bool isRound = false; // shape rect(false) circle(true) + int32_t originWidth = 0; // or width + int32_t originHeight = 0; // or height + int32_t compressWidth = 0; // cr width + int32_t compressHeight = 0; // cr height + Orientation orientation = Orientation::PORTRAIT; // orientation + double density = 1.0; // dpi with calculate + DeviceType deviceType = DeviceType::PHONE; // device type + ColorMode colorMode = ColorMode::LIGHT; // color mode +}; + +class PreviewerWindow { +public: + PreviewerWindow(const PreviewerWindow&) = delete; + PreviewerWindow& operator=(const PreviewerWindow&) = delete; + ~PreviewerWindow() = default; + + static PreviewerWindow& GetInstance(); + + void SetWindowParams(const PreviewerWindowModel& windowModel); + PreviewerWindowModel& GetWindowParams(); + + void SetWindowObject(const Rosen::WindowImpl *window); + Rosen::WindowImpl* GetWindowObject(); + +private: + PreviewerWindow(); + PreviewerWindowModel windowModel; + Rosen::WindowImpl *window; +}; +} // namespace Previewer +} // namespace OHOS +#endif // INTERFACES_INNERKITS_WINDOW_MODEL_H diff --git a/previewer/src/window_model.cpp b/previewer/src/window_model.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6244a2ea9997758ff505f8b7e614645f674fdc9 --- /dev/null +++ b/previewer/src/window_model.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "window_model.h" + +namespace OHOS { +namespace Previewer { + +PreviewerWindow::PreviewerWindow() +{ +} + +PreviewerWindow& PreviewerWindow::GetInstance() +{ + static PreviewerWindow instance; + return instance; +} + +void PreviewerWindow::SetWindowParams(const PreviewerWindowModel& windowModel) +{ + this->windowModel = windowModel; +} + +PreviewerWindowModel& PreviewerWindow::GetWindowParams() +{ + return this->windowModel; +} + +void PreviewerWindow::SetWindowObject(const Rosen::WindowImpl *window) +{ + this->window = const_cast(window); +} + +Rosen::WindowImpl* PreviewerWindow::GetWindowObject() +{ + return this->window; +} + +} // namespace Previewer +} // namespace OHOS \ No newline at end of file