SnippingWindow::SnippingWindow(HWND _parent)
    :WindowBase()
{
    auto up = std::make_unique<Yupei::CreateParam>(L"YupeiWindow");
    up->ParentWindow = _parent;
    SetCreateParam(std::move(up));
    auto rect = Yupei::DeviceHelper::GetResolution(GetWindowHandle());
    resolutionX = Yupei::GetRECTWidth<UINT>(rect);
    resolutionY = Yupei::GetRECTHeight<UINT>(rect);
    auto rt = GetRenderTarget();
    rt->CreateLayer(&topLayer);
    rt->CreateLayer(&shownLayer);
    rt->CreateSolidColorBrush(
        D2D1::ColorF(D2D1::ColorF::White, 0.5f), &whiteBrush);

}
Beispiel #2
0
int __stdcall wWinMain(HINSTANCE instance, HINSTANCE,
                       wchar_t* cmdline, int cmd_show) {

  ::CoInitializeEx(NULL, COINIT_MULTITHREADED);

  try {
    DCoWindow window;
    
    // Create device independent resources. FactoryD2D1 and Geometries are such.
    auto wic_factory = plx::CreateWICFactory();
#if defined (_DEBUG)
    auto d2d1_factory = plx::CreateD2D1FactoryST(D2D1_DEBUG_LEVEL_INFORMATION);
#else
    auto d2d1_factory = plx::CreateD2D1FactoryST(D2D1_DEBUG_LEVEL_NONE);
#endif
    const auto circle =  D2D1::Ellipse(D2D1::Point2F(50.0f, 50.0f), 49.0f, 49.0f);
    plx::ComPtr<ID2D1EllipseGeometry> circle_geom;
    auto hr = d2d1_factory->CreateEllipseGeometry(circle, circle_geom.GetAddressOf());
    if (hr != S_OK)
      throw plx::ComException(__LINE__, hr);

    // Device dependent resources.
#if defined (_DEBUG)
    auto device3D = plx::CreateDeviceD3D11(D3D11_CREATE_DEVICE_DEBUG);
#else
    auto device3D = plx::CreateDevice3D(0);
#endif
    auto device2D = plx::CreateDeviceD2D1(device3D, d2d1_factory);

    VisualManager viman(window.window(), window.dpi(), device2D);
    window.set_visual_manager(&viman);

    const D2D1_SIZE_F zero_offset = {0};

    auto background = viman.make_surface(1.0f, 1.0f);
    {
      auto dc = background.begin_draw(D2D1::ColorF(0.3f, 0.3f, 0.3f, 0.7f), zero_offset);
      background.end_draw();
    }
    viman.set_background_surface(window.window(), background);


    // scale-dependent resources.
    auto surface1 = viman.make_surface(100.0f, 100.0f);
    {
      auto dc = surface1.begin_draw(D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.0f), zero_offset);
      plx::ComPtr<ID2D1SolidColorBrush> brush;
      dc->CreateSolidColorBrush(D2D1::ColorF(0.0f, 0.5f, 1.0f, 0.4f), brush.GetAddressOf());
      dc->FillGeometry(circle_geom.Get(), brush.Get());
      brush->SetColor(D2D1::ColorF(1.0f, 1.0f, 1.0f));
      dc->DrawGeometry(circle_geom.Get(), brush.Get());
      surface1.end_draw();
    }

    unsigned int as_width, as_height;
    auto png1 = plx::CreateWICDecoder(
        wic_factory, plx::FilePath(L"c:\\test\\images\\diamonds_k.png"));
    auto png1_cv = plx::CreateWICBitmapBGRA(0, WICBitmapDitherTypeNone, png1, wic_factory);
    png1_cv->GetSize(&as_width, &as_height);

    auto sc_width = window.dpi().to_physical_x(as_width * 0.5f);
    auto sc_height = window.dpi().to_physical_y(as_height * 0.5f);
    auto surface2 = viman.make_surface(sc_width, sc_height);
    {
      auto dc = surface2.begin_draw(D2D1::ColorF(0.0f, 0.0f, 0.4f, 0.0f), zero_offset);
      auto bmp1 = CreateD2D1Bitmap(dc, png1_cv);
      auto dr = D2D1::Rect(0.0f, 0.0f, sc_width, sc_height);
      dc->DrawBitmap(bmp1.Get(), &dr, 1.0f);
      surface2.end_draw();
    }

    // add the image at the bottom.
    viman.add_visual(surface2, D2D1::Point2F(0.0f, 0.0f));

    auto svg = RealizeSVG(
        //"C:\\Users\\cpu\\Documents\\GitHub\\nanosvg\\example\\nano.svg",
        //"C:\\Test\\svg\\2_elipse_red_black.svg",
        "C:\\Test\\svg\\3_red_arrows_angles.svg",
        window.dpi(), d2d1_factory);

    D2D1_RECT_F svg_bounds = {};
    hr = svg->GetBounds(nullptr, &svg_bounds);
    auto surface3 = viman.make_surface(
        window.dpi().to_physical_x(svg_bounds.right - svg_bounds.left + 1),
        window.dpi().to_physical_y(svg_bounds.bottom - svg_bounds.top + 1));
    {
      auto dc = surface3.begin_draw(
           D2D1::ColorF(0.7f, 0.7f, 0.7f, 0.4f), 
           D2D1::SizeF(-svg_bounds.left, -svg_bounds.top));
      plx::ComPtr<ID2D1SolidColorBrush> brush;
      dc->CreateSolidColorBrush(
          D2D1::ColorF(0.5f, 0.0f, 1.0f, 0.4f), brush.GetAddressOf());
      // Now we can paint and we can draw.
      dc->FillGeometry(svg.Get(), brush.Get());
      brush->SetColor(D2D1::ColorF(1.0f, 1.0f, 1.0f));
      dc->DrawGeometry(svg.Get(), brush.Get());
      surface3.end_draw();
    }

    viman.add_visual(surface3, D2D1::Point2F(10.0f, 80.0f));

    // Add some elipses on top.
    for (int ix = 0; ix != 5; ++ix) {
      viman.add_visual(surface1, D2D1::Point2F(125.0f * ix, 45.0f * ix));
    }

    viman.commit();
    
    HACCEL accel_table = ::LoadAccelerators(instance, MAKEINTRESOURCE(IDC_VTESTS));
    MSG msg;
    while (::GetMessage(&msg, NULL, 0, 0)) {
      if (!::TranslateAccelerator(msg.hwnd, accel_table, &msg)) {
        ::TranslateMessage(&msg);
        ::DispatchMessage(&msg);
      }
    }

    return (int) msg.wParam;

  } catch (plx::Exception& ex) {
    ex;
    __debugbreak();
    return -1;
  }
}