zoukankan      html  css  js  c++  java
  • 任意角度旋转

    今天解决用户提出的新需求:要求图形对象能任意角度旋转。

    本来嘛,我做DrGraph图形软件只是为了画电路图,对象的位置状态只是横平竖直的,就90度的整数倍方向。没想到,要画的东东越来越多,现在,象液压图、气路图、思维图、流程图、框图、平面图、面板图…,一个个逐渐地加进来了。目前又多了个光路图。

    以前,我认为,不管要画什么图,大概也许可能应该都能画得出来。结果看到光路图,哦,原来还真画不出来。

    那就加上吧。

    仔细研究一下原来的程序代码,发现只需要加个属性就好了:

    double TCbwObject::RotateAngle;

    double GdiModule::RotateAngle;

    然后在画出前,加上

            TGlobalVariables::GdiModule.RotateAngle = RotateAngle;

    而画出时,加上旋转矩阵处理

        if(RotateAngle) {

            double x=0, y=0;

            for(int i = 0; i < pointNumber; ++i) {

                x += points[i].x;

                y += points[i].y;

            }

            if(pointNumber) {

                x /= pointNumber;

                y /= pointNumber;

            }

            GlobalMatrix = new Gdiplus::Matrix();

            GlobalMatrix->RotateAt(RotateAngle, Gdiplus::PointF(x, y), Gdiplus::MatrixOrder::MatrixOrderAppend);

    }

    Gdiplus::Graphics * __fastcall GetGraphicsForRotate(TCanvas * canvas) {

        Gdiplus::Graphics * g = new Gdiplus::Graphics(canvas->Handle);

        if (GlobalMatrix)

            g->SetTransform(GlobalMatrix);

    … // 同以前

    简单试一下:

    画出几个图元

    设置其旋转角度

    达到预期目标。

    下来只是进行IO设计,很简单的了。

    还有待改进的是:区域也需要跟进旋转,以方便选择。不过目前先解决用户的需求,让他们可以画图。

  • 相关阅读:
    docker镜像构建之docker commit(七)
    docker常用容器命令(五)
    docker常用镜像命令(四)
    如何查看systemctl启动服务的日志
    window server 2012 无法安装.NET framework 3.5 service pack 1
    SpringBoot第六篇-SpringBoot+Mybatis+SpringSecurity+JWT整合,开发工具IDea
    SpringBoot第五篇SpringSecurity 认证机制
    SpringBoot第四篇常见问题
    SpringBoot第三篇SpringBoo和Mybatis整合
    SpringBoot第二章拦截器
  • 原文地址:https://www.cnblogs.com/drgraph/p/3286544.html
Copyright © 2011-2022 走看看