diff options
author | crupest <crupest@outlook.com> | 2021-08-20 22:10:45 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-08-20 22:10:45 +0800 |
commit | e2e8ba559b0e7a797c083684b382ac4cbb2fdd5f (patch) | |
tree | 9b9e61142c490c53a5d7b3bba2c62ee6281a87db | |
parent | bcb879240f96764b8f17da2878fc0784c51b6054 (diff) | |
download | cru-e2e8ba559b0e7a797c083684b382ac4cbb2fdd5f.tar.gz cru-e2e8ba559b0e7a797c083684b382ac4cbb2fdd5f.tar.bz2 cru-e2e8ba559b0e7a797c083684b382ac4cbb2fdd5f.zip |
...
-rw-r--r-- | include/cru/osx/Exception.hpp | 10 | ||||
-rw-r--r-- | include/cru/osx/Resource.hpp | 13 | ||||
-rw-r--r-- | include/cru/osx/graphics/quartz/Factory.hpp (renamed from include/cru/osx/graphics/native/Factory.hpp) | 0 | ||||
-rw-r--r-- | include/cru/osx/graphics/quartz/Painter.hpp | 41 | ||||
-rw-r--r-- | include/cru/osx/graphics/quartz/Resource.hpp | 14 | ||||
-rw-r--r-- | src/common/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/osx/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/osx/Resource.cpp | 2 | ||||
-rw-r--r-- | src/osx/graphics/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/osx/graphics/native/CMakeLists.txt | 11 | ||||
-rw-r--r-- | src/osx/graphics/native/Factory.cpp | 1 | ||||
-rw-r--r-- | src/osx/graphics/quartz/CMakeLists.txt | 15 | ||||
-rw-r--r-- | src/osx/graphics/quartz/Factory.cpp | 1 | ||||
-rw-r--r-- | src/osx/graphics/quartz/Painter.cpp | 1 | ||||
-rw-r--r-- | src/osx/graphics/quartz/Resource.cpp | 0 |
15 files changed, 100 insertions, 19 deletions
diff --git a/include/cru/osx/Exception.hpp b/include/cru/osx/Exception.hpp index 34c4a06c..5d057c65 100644 --- a/include/cru/osx/Exception.hpp +++ b/include/cru/osx/Exception.hpp @@ -2,8 +2,8 @@ #include "cru/platform/Exception.hpp" namespace cru::platform::osx { - class OsxException : PlatformException { - public: - using PlatformException::PlatformException; - }; -} +class OsxException : public PlatformException { + public: + using PlatformException::PlatformException; +}; +} // namespace cru::platform::osx diff --git a/include/cru/osx/Resource.hpp b/include/cru/osx/Resource.hpp new file mode 100644 index 00000000..b1f673f8 --- /dev/null +++ b/include/cru/osx/Resource.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "cru/platform/Resource.hpp" + +namespace cru::platform::osx { +class OsxResource : public Object, public virtual IPlatformResource { + public: + CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(OsxResource) + CRU_DELETE_COPY(OsxResource) + CRU_DELETE_MOVE(OsxResource) + + String GetPlatformId() const override { return u"OSX"; } +}; +} // namespace cru::platform::osx diff --git a/include/cru/osx/graphics/native/Factory.hpp b/include/cru/osx/graphics/quartz/Factory.hpp index 6f70f09b..6f70f09b 100644 --- a/include/cru/osx/graphics/native/Factory.hpp +++ b/include/cru/osx/graphics/quartz/Factory.hpp diff --git a/include/cru/osx/graphics/quartz/Painter.hpp b/include/cru/osx/graphics/quartz/Painter.hpp new file mode 100644 index 00000000..2d77ab3a --- /dev/null +++ b/include/cru/osx/graphics/quartz/Painter.hpp @@ -0,0 +1,41 @@ +#pragma once +#include "Resource.hpp" +#include "cru/platform/graphics/Painter.hpp" + +#include <CoreGraphics/CoreGraphics.h> + +namespace cru::platform::graphics::osx::quartz { +class QuartzCGContextPainter : public OsxQuartzResource, + public virtual IPainter { + public: + explicit QuartzCGContextPainter(CGContext* cg_context) + : cg_context_(cg_context) {} + + public: + Matrix GetTransform() override; + void SetTransform(const Matrix& matrix) override; + + void Clear(const Color& color) override; + + void DrawLine(const Point& start, const Point& end, IBrush* brush, + float width) override; + void StrokeRectangle(const Rect& rectangle, IBrush* brush, + float width) override; + void FillRectangle(const Rect& rectangle, IBrush* brush) override; + + void StrokeGeometry(IGeometry* geometry, IBrush* brush, float width) override; + void FillGeometry(IGeometry* geometry, IBrush* brush) override; + + void DrawText(const Point& offset, ITextLayout* text_layout, + IBrush* brush) override; + + void PushLayer(const Rect& bounds) override; + + void PopLayer() override; + + void EndDraw() override; + + private: + CGContext* cg_context_; +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/include/cru/osx/graphics/quartz/Resource.hpp b/include/cru/osx/graphics/quartz/Resource.hpp new file mode 100644 index 00000000..b302c84c --- /dev/null +++ b/include/cru/osx/graphics/quartz/Resource.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "cru/osx/Resource.hpp" + +namespace cru::platform::graphics::osx::quartz { +class OsxQuartzResource : public platform::osx::OsxResource { + public: + CRU_DEFAULT_CONSTRUCTOR_DESTRUCTOR(OsxQuartzResource) + CRU_DELETE_COPY(OsxQuartzResource) + CRU_DELETE_MOVE(OsxQuartzResource) + + public: + String GetPlatformId() const override { return u"OSX Quartz"; } +}; +} // namespace cru::platform::graphics::osx::quartz diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 94961746..71648589 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -22,8 +22,10 @@ target_compile_definitions(cru_base PRIVATE CRU_BASE_EXPORT_API) if (WIN32) target_compile_definitions(cru_base PUBLIC CRU_PLATFORM_WINDOWS) +elseif(APPLE) + target_compile_definitions(cru_base PUBLIC CRU_PLATFORM_OSX) else() - target_compile_definitions(cru_base PUBLIC CRU_PLATFORM_UNIX) + target_compile_definitions(cru_base PUBLIC CRU_PLATFORM_LINUX) endif() find_package(Microsoft.GSL CONFIG REQUIRED) diff --git a/src/osx/CMakeLists.txt b/src/osx/CMakeLists.txt index 8013a5d6..0957050a 100644 --- a/src/osx/CMakeLists.txt +++ b/src/osx/CMakeLists.txt @@ -2,10 +2,14 @@ set(CRU_OSX_BASE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/osx) add_library(cru_osx_base SHARED Exception.cpp + Resource.cpp ) target_sources(cru_osx_base PUBLIC ${CRU_OSX_BASE_INCLUDE_DIR}/Exception.hpp + ${CRU_OSX_BASE_INCLUDE_DIR}/Resource.hpp ) +target_link_libraries(cru_osx_base PUBLIC cru_platform_base) + add_subdirectory(graphics) diff --git a/src/osx/Resource.cpp b/src/osx/Resource.cpp new file mode 100644 index 00000000..76381d14 --- /dev/null +++ b/src/osx/Resource.cpp @@ -0,0 +1,2 @@ +#include "cru/osx/Resource.hpp" + diff --git a/src/osx/graphics/CMakeLists.txt b/src/osx/graphics/CMakeLists.txt index 91ffbfaf..980c2f93 100644 --- a/src/osx/graphics/CMakeLists.txt +++ b/src/osx/graphics/CMakeLists.txt @@ -1 +1 @@ -add_subdirectory(native) +add_subdirectory(quartz) diff --git a/src/osx/graphics/native/CMakeLists.txt b/src/osx/graphics/native/CMakeLists.txt deleted file mode 100644 index 610292da..00000000 --- a/src/osx/graphics/native/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/osx/graphics/native) - -add_library(cru_win_graphics_direct SHARED - Factory.cpp -) -target_sources(cru_win_graphics_direct PUBLIC - ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Factory.hpp -) -target_link_libraries(cru_win_graphics_direct PUBLIC cocoa) -target_link_libraries(cru_win_graphics_direct PUBLIC cru_osx_base cru_platform_graphics) - diff --git a/src/osx/graphics/native/Factory.cpp b/src/osx/graphics/native/Factory.cpp deleted file mode 100644 index 0025ca3e..00000000 --- a/src/osx/graphics/native/Factory.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "cru/osx/graphics/native/Factory.hpp" diff --git a/src/osx/graphics/quartz/CMakeLists.txt b/src/osx/graphics/quartz/CMakeLists.txt new file mode 100644 index 00000000..41577ad7 --- /dev/null +++ b/src/osx/graphics/quartz/CMakeLists.txt @@ -0,0 +1,15 @@ +set(CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR ${CRU_INCLUDE_DIR}/cru/osx/graphics/quartz) + +add_library(cru_osx_graphics_quartz SHARED + Factory.cpp + Painter.cpp + Resource.cpp +) +target_sources(cru_osx_graphics_quartz PUBLIC + ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Factory.hpp + ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Painter.hpp + ${CRU_OSX_GRAPHICS_NATIVE_INCLUDE_DIR}/Resource.hpp +) +target_link_libraries(cru_osx_graphics_quartz PUBLIC cocoa) +target_link_libraries(cru_osx_graphics_quartz PUBLIC cru_osx_base cru_platform_graphics) + diff --git a/src/osx/graphics/quartz/Factory.cpp b/src/osx/graphics/quartz/Factory.cpp new file mode 100644 index 00000000..f9b792f2 --- /dev/null +++ b/src/osx/graphics/quartz/Factory.cpp @@ -0,0 +1 @@ +#include "cru/osx/graphics/quartz/Factory.hpp" diff --git a/src/osx/graphics/quartz/Painter.cpp b/src/osx/graphics/quartz/Painter.cpp new file mode 100644 index 00000000..b3006a97 --- /dev/null +++ b/src/osx/graphics/quartz/Painter.cpp @@ -0,0 +1 @@ +#include "cru/osx/graphics/quartz/Painter.hpp" diff --git a/src/osx/graphics/quartz/Resource.cpp b/src/osx/graphics/quartz/Resource.cpp new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/src/osx/graphics/quartz/Resource.cpp |