void drawLine(ID2D1DeviceContext* context, const Float2& zoomRatio, const Int2& pos1, const Int2& pos2, const Color& color, float thickness) { D2D1::ColorF colorDx(color.r() / 256.f, color.g() / 256.f, color.b() / 256.f, color.a() / 256.f); //D2D1::ColorF colorDx = D2D1::ColorF::MidnightBlue; ID2D1SolidColorBrush* solidBrush; DX::ThrowIfFailed(context->CreateSolidColorBrush(colorDx, &solidBrush)); D2D1_POINT_2F pt1; pt1.x = zoomRatio.x() + (float)pos1.x(); pt1.y = zoomRatio.y() + (float)pos1.y(); D2D1_POINT_2F pt2; pt2.x = zoomRatio.x() + (float)pos2.x(); pt2.y = zoomRatio.y() + (float)pos2.y(); context->SetTransform(D2D1::Matrix3x2F::Identity()); //s_context->SetDpi(DirectXDraw::getDefaultDpi().x(), DirectXDraw::getDefaultDpi().y()); context->DrawLine(pt1, pt2, solidBrush, thickness); solidBrush->Release(); //delete solidBrush; }
void drawRoundedRectangle(ID2D1DeviceContext* context, const Float2& zoomRatio, const Int2& posLeftTop, const Int2& posRightBottom, const Color& color, float round, float borderSize, bool fill) { D2D1::ColorF colorDx(color.r() / 256.f, color.g() / 256.f, color.b() / 256.f, color.a() / 256.f); ID2D1SolidColorBrush* solidBrush; DX::ThrowIfFailed(context->CreateSolidColorBrush(colorDx, &solidBrush)); D2D1_ROUNDED_RECT rrect; rrect.radiusX = round; rrect.radiusY = round; rrect.rect.left = zoomRatio.x() + (float)posLeftTop.x(); rrect.rect.top = zoomRatio.y() + (float)posLeftTop.y(); rrect.rect.right = zoomRatio.x() + (float)posRightBottom.x(); rrect.rect.bottom = zoomRatio.y() + (float)posRightBottom.y(); context->SetTransform(D2D1::Matrix3x2F::Identity()); if (fill) context->FillRoundedRectangle(rrect, solidBrush); //if (borderSize > 0.f) context->DrawRoundedRectangle(rrect, solidBrush, borderSize); solidBrush->Release(); //delete solidBrush; }
Int2 AppSetup::getSizeOrtho2DWindow() const { Float2 ppp = this->getPixelPerPoint(); return Int2((int)((float)m_inf.windowSize.x() / ppp.x()), (int)((float)m_inf.windowSize.y() / ppp.y())); }
void drawBitmap( ID2D1DeviceContext* context, const Float2& zoomRatio, const Float2& m_defaultDpi, ID2D1Bitmap* bitmap, const Float2& position, const Float2& scale, float opacity, D2D1_RECT_F* rectSource, D2D1_RECT_F* rectDest, float angleDegree, const Int2& rotationCenterPos, bool horizontalMirror, bool verticalMirror) { D2D1_MATRIX_3X2_F transformTmp; context->GetTransform(&transformTmp); D2D1::Matrix3x2F matTranslation = D2D1::Matrix3x2F::Translation(zoomRatio.x() + position.x(), zoomRatio.y() + position.y());// / scale.x() / scale.y() if (angleDegree != 0.f || horizontalMirror || verticalMirror) { D2D1::Matrix3x2F matMirroring = D2D1::Matrix3x2F::Scale(horizontalMirror ? -1.f : 1.f, verticalMirror ? -1.f : 1.f); D2D1_POINT_2F imageRotationCenterPos = D2D1::Point2F((float)rotationCenterPos.x(), (float)rotationCenterPos.y()); D2D1::Matrix3x2F matRotation = D2D1::Matrix3x2F::Rotation(angleDegree, imageRotationCenterPos); context->SetTransform(matMirroring * matRotation * matTranslation); } else { context->SetTransform(matTranslation);// * s_ppp.x() * s_ppp.y() } //Assert(scale.x() > 0.f && scale.y() > 0.f); // note about bitmaps: https://msdn.microsoft.com/en-us/library/windows/desktop/dd371150%28v=vs.85%29.aspx Float2 dpiBitmap; bitmap->GetDpi(&dpiBitmap.data[0], &dpiBitmap.data[1]); Float2 scaleToApply = dpiBitmap / m_defaultDpi * scale;//s_ppp * dpiBitmap / dpiContext * scale; D2D1_RECT_F rectDestFinal; if (rectDest == 0) { D2D1_SIZE_F sz = bitmap->GetSize(); rectDestFinal.left = 0.f; rectDestFinal.top = 0.f; rectDestFinal.right = sz.width * scaleToApply.x(); rectDestFinal.bottom = sz.height *scaleToApply.y(); context->DrawBitmap(bitmap, &rectDestFinal, opacity, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, rectSource); } else { rectDestFinal = *rectDest; rectDestFinal.left *= scaleToApply.x(); rectDestFinal.top *= scaleToApply.y(); rectDestFinal.right *= scaleToApply.x(); rectDestFinal.bottom *= scaleToApply.y(); Float2 srcScaleToApply = dpiBitmap / m_defaultDpi; D2D1_RECT_F rectSourceFinal; rectSourceFinal = *rectSource; rectSourceFinal.left /= srcScaleToApply.x(); rectSourceFinal.top /= srcScaleToApply.y(); rectSourceFinal.right /= srcScaleToApply.x(); rectSourceFinal.bottom /= srcScaleToApply.y(); context->DrawBitmap(bitmap, &rectDestFinal, opacity, D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, &rectSourceFinal); } context->SetTransform(transformTmp);//D2D1::Matrix3x2F::Translation(0.f, 0.f)); //s_context->Flush(); }
void drawTextLayout(ID2D1DeviceContext* context, const Float2& zoomRatio, ID2D1SolidColorBrush* solidBrush, IDWriteTextLayout* textLayout, const Int2& position, const Float2& scale) { D2D1_MATRIX_3X2_F transformTmp; context->GetTransform(&transformTmp); context->SetTransform(D2D1::Matrix3x2F::Translation(zoomRatio.x() + (float)position.x() / scale.x(), zoomRatio.y() + (float)position.y() / scale.y()));// * s_ppp.x() * s_ppp.y( // TODO scale with s_ppp context->DrawTextLayout(D2D1::Point2F(0.0f, 0.0f), textLayout, solidBrush); context->SetTransform(transformTmp); }