aboutsummaryrefslogtreecommitdiff
path: root/demos/graphics/DrawCircle.cpp
blob: 13a7367a9edb602717132118bd274498615a4e8e (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
28
29
30
31
32
33
34
35
#include "cru/common/io/FileStream.h"
#include "cru/common/io/OpenFileFlag.h"
#include "cru/platform/Color.h"
#include "cru/platform/bootstrap/Bootstrap.h"
#include "cru/platform/graphics/Factory.h"
#include "cru/platform/graphics/ImageFactory.h"
#include "cru/platform/graphics/Painter.h"

#include <memory>

int main() {
  std::unique_ptr<cru::platform::graphics::IGraphicsFactory> graphics_factory(
      cru::platform::bootstrap::CreateGraphicsFactory());

  auto image = graphics_factory->GetImageFactory()->CreateBitmap(500, 500);

  {
    auto brush =
        graphics_factory->CreateSolidColorBrush(cru::platform::colors::black);
    auto painter = image->CreatePainter();
    painter->FillEllipse(cru::platform::Rect{200, 200, 100, 100}, brush.get());
    painter->EndDraw();
  }

  cru::io::FileStream file_stream(u"./test_image.png",
                                  cru::io::OpenFileFlags::Write |
                                      cru::io::OpenFileFlags::Create |
                                      cru::io::OpenFileFlags::Truncate);

  graphics_factory->GetImageFactory()->EncodeToStream(
      image.get(), &file_stream, cru::platform::graphics::ImageFormat::Png,
      1.0f);

  return 0;
}