Introduce WindowData 55/290155/9
authorDaekwang Ryu <dkdk.ryu@samsung.com>
Fri, 14 Apr 2023 02:45:37 +0000 (11:45 +0900)
committerDaekwang Ryu <dkdk.ryu@samsung.com>
Fri, 14 Apr 2023 02:45:37 +0000 (11:45 +0900)
The application class had to add new consructors whenever the Window
class added a new constructor. Becuase the class has a default window.
To simplify this process, WindowData is introduced that contains
all the data of the window.

Change-Id: Ib7a334e5d705628b4498e7775cd810f1f3ba50d8

automated-tests/src/dali-adaptor/CMakeLists.txt
automated-tests/src/dali-adaptor/utc-Dali-Application.cpp
automated-tests/src/dali-adaptor/utc-Dali-WindowData.cpp [new file with mode: 0644]
dali/dali.h
dali/public-api/adaptor-framework/application.cpp
dali/public-api/adaptor-framework/application.h
dali/public-api/adaptor-framework/window-data.cpp [new file with mode: 0644]
dali/public-api/adaptor-framework/window-data.h [new file with mode: 0644]
dali/public-api/file.list

index f4c425e..ecbe6f8 100644 (file)
@@ -8,6 +8,7 @@ SET(TC_SOURCES
     utc-Dali-Application.cpp
     utc-Dali-EncodedImageBuffer.cpp
     utc-Dali-Capture.cpp
+    utc-Dali-WindowData.cpp
     utc-Dali-FileLoader.cpp
     utc-Dali-GifLoading.cpp
     utc-Dali-Gl-Window.cpp
index a760954..7261b37 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -181,6 +181,22 @@ int UtcDaliApplicationNew07P(void)
   END_TEST;
 }
 
+int UtcDaliApplicationNew08P(void)
+{
+  int         argc(1);
+  const char* argList[1] = {"program"};
+  char**      argv       = const_cast<char**>(argList);
+  WindowData  windowData;
+
+  Application application = Application::New(&argc, &argv, "stylesheet", false, windowData);
+
+  MyTestApp testApp(application);
+
+  DALI_TEST_CHECK(application);
+
+  END_TEST;
+}
+
 int UtcDaliApplicationCopyAndAssignment(void)
 {
   Application application = Application::New();
diff --git a/automated-tests/src/dali-adaptor/utc-Dali-WindowData.cpp b/automated-tests/src/dali-adaptor/utc-Dali-WindowData.cpp
new file mode 100644 (file)
index 0000000..abe4286
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics 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 <dali-test-suite-utils.h>
+#include <dali/public-api/adaptor-framework/window-data.h>
+
+using namespace Dali;
+
+int UtcDaliWindowData01(void)
+{
+  // Test default values
+  WindowData windowData;
+
+  DALI_TEST_CHECK(windowData.GetWindowType() == WindowType::NORMAL);
+  DALI_TEST_CHECK(windowData.GetTransparency() == true);
+  DALI_TEST_CHECK(windowData.GetPositionSize().x == 0);
+  DALI_TEST_CHECK(windowData.GetPositionSize().y == 0);
+  DALI_TEST_CHECK(windowData.GetPositionSize().width == 0);
+  DALI_TEST_CHECK(windowData.GetPositionSize().height == 0);
+
+  END_TEST;
+}
+
+int UtcDaliWindowData02(void)
+{
+  // Test SetTransparency and GetTransparency
+  WindowData windowData;
+  windowData.SetTransparency(false);
+
+  DALI_TEST_CHECK(windowData.GetTransparency() == false);
+
+  END_TEST;
+}
+
+int UtcDaliWindowData03(void)
+{
+  // Test SetWindowType and GetWindowType
+  WindowData windowData;
+  windowData.SetWindowType(WindowType::UTILITY);
+
+  DALI_TEST_CHECK(windowData.GetWindowType() == WindowType::UTILITY);
+
+  END_TEST;
+}
+
+int UtcDaliWindowData04(void)
+{
+  // Test SetPositionSize and GetPositionSize
+  WindowData      windowData;
+  Dali::Rect<int> rect(100, 200, 300, 400);
+  windowData.SetPositionSize(rect);
+
+  DALI_TEST_CHECK(windowData.GetPositionSize().x == 100);
+  DALI_TEST_CHECK(windowData.GetPositionSize().y == 200);
+  DALI_TEST_CHECK(windowData.GetPositionSize().width == 300);
+  DALI_TEST_CHECK(windowData.GetPositionSize().height == 400);
+
+  END_TEST;
+}
index ff3b7df..db4687d 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
 #include <dali/public-api/adaptor-framework/widget-application.h>
 #include <dali/public-api/adaptor-framework/widget-impl.h>
 #include <dali/public-api/adaptor-framework/widget.h>
+#include <dali/public-api/adaptor-framework/window-data.h>
 #include <dali/public-api/dali-adaptor-version.h>
 
-#endif //DALI_H
+#endif // DALI_H
index 8ed1f90..36db754 100644 (file)
@@ -123,6 +123,34 @@ Application Application::New(int* argc, char** argv[], const std::string& styles
   return Application(internal.Get());
 }
 
+Application Application::New(int* argc, char** argv[], const std::string& stylesheet, bool useUiThread, WindowData& windowData)
+{
+  Internal::Adaptor::ApplicationPtr internal = Internal::Adaptor::Application::GetPreInitializedApplication();
+  if(internal)
+  {
+    // pre-initialized application
+    internal->SetCommandLineOptions(argc, argv);
+    internal->SetStyleSheet(stylesheet);
+
+    // Set defaut Window type
+    internal->SetDefaultWindowType(windowData.GetWindowType());
+    internal->GetWindow().SetTransparency(windowData.GetTransparency());
+
+    // Store only the value before adaptor is created
+    internal->StoreWindowPositionSize(windowData.GetPositionSize());
+  }
+  else
+  {
+    // clang-format off
+    internal = Internal::Adaptor::Application::New(argc, argv, stylesheet,
+                  windowData.GetTransparency() ? WINDOW_MODE::TRANSPARENT : WINDOW_MODE::OPAQUE,
+                  windowData.GetPositionSize(), Internal::Adaptor::Framework::NORMAL,
+                  windowData.GetWindowType(), useUiThread);
+    // clang-format on
+  }
+  return Application(internal.Get());
+}
+
 Application::~Application()
 {
 }
index 1971c4d..c8ca3be 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_APPLICATION_H
 
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/public-api/adaptor-framework/device-status.h>
+#include <dali/public-api/adaptor-framework/window-data.h>
 #include <dali/public-api/adaptor-framework/window.h>
 
 namespace Dali
@@ -224,6 +225,24 @@ public:
   static Application New(int* argc, char** argv[], const std::string& stylesheet, Application::WINDOW_MODE windowMode, PositionSize positionSize, bool useUiThread);
 
   /**
+   * @brief This is the constructor for applications.
+   *
+   * @SINCE_2_2.23
+   * @PRIVLEVEL_PUBLIC
+   * @PRIVILEGE_DISPLAY
+   * @param[in,out]  argc         A pointer to the number of arguments
+   * @param[in,out]  argv         A pointer to the argument list
+   * @param[in]      stylesheet   The path to user defined theme file
+   * @param[in]      useUiThread  True if the application would create a UI thread
+   * @param[in]      windowData   The window data for the application
+   * @return A handle to the Application
+   * @note If the stylesheet is not specified, then the library's default stylesheet will not be overridden.<BR>
+   * UI thread is an additional thread that DALi creates for UI events.
+   * The UI thread isn't blocked from the system events(AppControl, LanguageChanged, RegionChanged, LowMemory, LowBattery task signals).
+   */
+  static Application New(int* argc, char** argv[], const std::string& stylesheet, bool useUiThread, WindowData& windowData);
+
+  /**
    * @brief Constructs an empty handle.
    * @SINCE_1_0.0
    */
diff --git a/dali/public-api/adaptor-framework/window-data.cpp b/dali/public-api/adaptor-framework/window-data.cpp
new file mode 100644 (file)
index 0000000..6d329bb
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics 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.
+ *
+ */
+
+// CLASS HEADER
+#include <dali/public-api/adaptor-framework/window-data.h>
+
+namespace Dali
+{
+struct WindowData::Impl
+{
+  Impl()
+  : mPositionSize(0, 0, 0, 0),
+    mIsTransparent(true),
+    mWindowType(WindowType::NORMAL)
+  {
+  }
+
+  Dali::Rect<int> mPositionSize;  ///< The position and size of the Window
+  bool            mIsTransparent; ///< The transparency of the Window
+  WindowType      mWindowType;    ///< The window type of the Window
+};
+
+WindowData::WindowData()
+: mImpl(std::make_unique<Impl>())
+{
+}
+
+WindowData::~WindowData() = default;
+
+void WindowData::SetPositionSize(Dali::Rect<int>& positionSize)
+{
+  mImpl->mPositionSize = positionSize;
+}
+
+Dali::Rect<int> WindowData::GetPositionSize() const
+{
+  return mImpl->mPositionSize;
+}
+
+void WindowData::SetTransparency(bool transparent)
+{
+  mImpl->mIsTransparent = transparent;
+}
+
+bool WindowData::GetTransparency() const
+{
+  return mImpl->mIsTransparent;
+}
+
+void WindowData::SetWindowType(WindowType type)
+{
+  mImpl->mWindowType = type;
+}
+
+WindowType WindowData::GetWindowType() const
+{
+  return mImpl->mWindowType;
+}
+
+} // namespace Dali
diff --git a/dali/public-api/adaptor-framework/window-data.h b/dali/public-api/adaptor-framework/window-data.h
new file mode 100644 (file)
index 0000000..b7bf089
--- /dev/null
@@ -0,0 +1,109 @@
+#ifndef DALI_WINDOW_DATA_H
+#define DALI_WINDOW_DATA_H
+
+/*
+ * Copyright (c) 2023 Samsung Electronics 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.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/adaptor-framework/window-enumerations.h>
+#include <dali/public-api/dali-adaptor-common.h>
+#include <dali/public-api/math/rect.h>
+#include <memory>
+
+namespace Dali
+{
+/**
+ * The WindowData class is used as a parameter for the constructors of the Application class.
+ * The data from the WindowData object is used to customize the default window created by the Application class.
+ *
+ * The default values are below:
+ * PositionSize : x:0, y:0, w:0, h:0 (full-screen window)
+ * Transparency : true (Window is created with 32-bit color depth)
+ * WindowType : NORMAL
+ *
+ * If you want to customize the window, you can modify the values of the WindowData object as needed.
+ * @SINCE_2_2.23
+ */
+class DALI_ADAPTOR_API WindowData
+{
+public:
+  /**
+   * @brief Creates a WindowData object.
+   */
+  WindowData();
+
+  /**
+   * @brief Destructor.
+   */
+  ~WindowData();
+
+  /**
+   * @brief Sets the position and size
+   *
+   * @SINCE_2_2.23
+   * @param[in] positionSize Position and Size
+   */
+  void SetPositionSize(Dali::Rect<int>& positionSize);
+
+  /**
+   * @brief Gets the PositionSize
+   *
+   * @SINCE_2_2.23
+   * @return The position and size
+   */
+  Dali::Rect<int> GetPositionSize() const;
+
+  /**
+   * @brief Sets the transparency
+   *
+   * @SINCE_2_2.23
+   * @param[in] transparent transparency
+   */
+  void SetTransparency(bool transparent);
+
+  /**
+   * @brief Gets the transparency
+   *
+   * @SINCE_2_2.23
+   * @return whether transparency
+   */
+  bool GetTransparency() const;
+
+  /**
+   * @brief Sets the window type
+   *
+   * @SINCE_2_2.23
+   * @param[in] type the window type
+   */
+  void SetWindowType(WindowType type);
+
+  /**
+   * @brief Gets the window type
+   *
+   * @SINCE_2_2.23
+   * @return the window type
+   */
+  WindowType GetWindowType() const;
+
+private:
+  struct Impl;
+  std::unique_ptr<Impl> mImpl;
+};
+
+} // namespace Dali
+
+#endif // DALI_WINDOW_DATA_H
index f13b5ff..4fbbab1 100644 (file)
@@ -12,6 +12,7 @@ SET( adaptor_public_api_src_files
   ${adaptor_public_api_dir}/adaptor-framework/widget-application.cpp
   ${adaptor_public_api_dir}/adaptor-framework/widget-impl.cpp
   ${adaptor_public_api_dir}/adaptor-framework/async-task-manager.cpp
+  ${adaptor_public_api_dir}/adaptor-framework/window-data.cpp
   ${adaptor_public_api_dir}/capture/capture.cpp
   ${adaptor_public_api_dir}/dali-adaptor-version.cpp
 )
@@ -41,6 +42,7 @@ SET( public_api_adaptor_framework_header_files
   ${adaptor_public_api_dir}/adaptor-framework/window-enumerations.h
   ${adaptor_public_api_dir}/adaptor-framework/round-robin-container-view.h
   ${adaptor_public_api_dir}/adaptor-framework/async-task-manager.h
+  ${adaptor_public_api_dir}/adaptor-framework/window-data.h
 )
 
 SET( public_dali_capture_header_files