aboutsummaryrefslogtreecommitdiff
path: root/demos/platform/graphics/DrawText.cpp
blob: dfea18cd5e3267a9d2329409e2030bb7a0f69a4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}