aboutsummaryrefslogtreecommitdiff
path: root/demos/Graphics
diff options
context:
space:
mode:
Diffstat (limited to 'demos/Graphics')
-rw-r--r--demos/Graphics/DrawCircle/CMakeLists.txt5
-rw-r--r--demos/Graphics/DrawCircle/CairoMain.cpp12
-rw-r--r--demos/Graphics/DrawCircle/DrawCircle.cpp29
-rw-r--r--demos/Graphics/DrawCircle/DrawCircle.h7
-rw-r--r--demos/Graphics/DrawCircle/PlatformMain.cpp12
5 files changed, 65 insertions, 0 deletions
diff --git a/demos/Graphics/DrawCircle/CMakeLists.txt b/demos/Graphics/DrawCircle/CMakeLists.txt
new file mode 100644
index 00000000..da6611ef
--- /dev/null
+++ b/demos/Graphics/DrawCircle/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_executable(CruDemoGraphicsDrawCircle DrawCircle.cpp PlatformMain.cpp)
+add_executable(CruDemoGraphicsDrawCircleCairo DrawCircle.cpp CairoMain.cpp)
+
+target_link_libraries(CruDemoGraphicsDrawCircle PRIVATE CruDemoBase)
+target_link_libraries(CruDemoGraphicsDrawCircleCairo PRIVATE CruDemoBase CruPlatformGraphicsCairo)
diff --git a/demos/Graphics/DrawCircle/CairoMain.cpp b/demos/Graphics/DrawCircle/CairoMain.cpp
new file mode 100644
index 00000000..35d6840b
--- /dev/null
+++ b/demos/Graphics/DrawCircle/CairoMain.cpp
@@ -0,0 +1,12 @@
+#include "cru/platform/graphics/cairo/CairoGraphicsFactory.h"
+
+#include "DrawCircle.h"
+
+int main() {
+ std::unique_ptr<cru::platform::graphics::IGraphicsFactory> graphics_factory(
+ new cru::platform::graphics::cairo::CairoGraphicsFactory());
+
+ cru::demos::graphics::DrawCircle(graphics_factory.get());
+
+ return 0;
+}
diff --git a/demos/Graphics/DrawCircle/DrawCircle.cpp b/demos/Graphics/DrawCircle/DrawCircle.cpp
new file mode 100644
index 00000000..aa73d44c
--- /dev/null
+++ b/demos/Graphics/DrawCircle/DrawCircle.cpp
@@ -0,0 +1,29 @@
+#include "cru/common/io/CFileStream.h"
+#include "cru/platform/Color.h"
+#include "cru/platform/graphics/Factory.h"
+#include "cru/platform/graphics/ImageFactory.h"
+#include "cru/platform/graphics/Painter.h"
+
+#include <memory>
+
+namespace cru::demos::graphics {
+ void DrawCircle(platform::graphics::IGraphicsFactory* graphics_factory) {
+
+ auto image = graphics_factory->GetImageFactory()->CreateBitmap(500, 500);
+
+ {
+ auto brush =
+ graphics_factory->CreateSolidColorBrush(cru::platform::colors::skyblue);
+ auto painter = image->CreatePainter();
+ painter->FillEllipse(cru::platform::Rect{200, 200, 100, 100}, brush.get());
+ painter->EndDraw();
+ }
+
+ cru::io::CFileStream file_stream("./test_image.png", "w");
+
+ graphics_factory->GetImageFactory()->EncodeToStream(
+ image.get(), &file_stream, cru::platform::graphics::ImageFormat::Png,
+ 1.0f);
+ }
+}
+
diff --git a/demos/Graphics/DrawCircle/DrawCircle.h b/demos/Graphics/DrawCircle/DrawCircle.h
new file mode 100644
index 00000000..8e14dc84
--- /dev/null
+++ b/demos/Graphics/DrawCircle/DrawCircle.h
@@ -0,0 +1,7 @@
+#pragma once
+#include "cru/platform/graphics/Factory.h"
+
+namespace cru::demos::graphics {
+ void DrawCircle(platform::graphics::IGraphicsFactory* graphics_factory);
+}
+
diff --git a/demos/Graphics/DrawCircle/PlatformMain.cpp b/demos/Graphics/DrawCircle/PlatformMain.cpp
new file mode 100644
index 00000000..3da1ec89
--- /dev/null
+++ b/demos/Graphics/DrawCircle/PlatformMain.cpp
@@ -0,0 +1,12 @@
+#include "cru/platform/bootstrap/Bootstrap.h"
+
+#include "DrawCircle.h"
+
+int main() {
+ std::unique_ptr<cru::platform::graphics::IGraphicsFactory> graphics_factory(
+ cru::platform::bootstrap::CreateGraphicsFactory());
+
+ cru::demos::graphics::DrawCircle(graphics_factory.get());
+
+ return 0;
+}