aboutsummaryrefslogtreecommitdiff
path: root/demos/platform/graphics/DrawText.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'demos/platform/graphics/DrawText.cpp')
-rw-r--r--demos/platform/graphics/DrawText.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/demos/platform/graphics/DrawText.cpp b/demos/platform/graphics/DrawText.cpp
new file mode 100644
index 00000000..dfea18cd
--- /dev/null
+++ b/demos/platform/graphics/DrawText.cpp
@@ -0,0 +1,27 @@
+#include "Base.h"
+#include "cru/platform/Color.h"
+#include "cru/platform/graphics/Factory.h"
+#include "cru/platform/graphics/Font.h"
+#include "cru/platform/graphics/Painter.h"
+
+#include <iostream>
+#include <memory>
+
+int main() {
+ CruPlatformGraphicsDemo demo("draw-text-demo.png", 500, 200);
+
+ auto brush =
+ demo.GetFactory()->CreateSolidColorBrush(cru::platform::colors::skyblue);
+
+ std::shared_ptr<cru::platform::graphics::IFont> font(
+ demo.GetFactory()->CreateFont(u"", 24));
+ auto text_layout = demo.GetFactory()->CreateTextLayout(font, u"Hello world!");
+ demo.GetPainter()->DrawText({0, 0}, text_layout.get(), brush.get());
+
+ auto bounds = text_layout->GetTextBounds();
+ std::cout << "Bounds of text:\n\tx: " << bounds.left
+ << "\n\ty: " << bounds.top << "\n\twidth: " << bounds.width
+ << "\n\theight: " << bounds.height << std::endl;
+
+ return 0;
+}