瀏覽代碼

CDR插件绘制圆形和矩形_版本02

蘭雅sRGB 6 月之前
父節點
當前提交
949f4166b0
共有 4 個文件被更改,包括 74 次插入16 次删除
  1. 26 0
      Makefile
  2. 43 13
      cdrapp.cpp
  3. 1 1
      cdrapp.h
  4. 4 2
      main.cpp

+ 26 - 0
Makefile

@@ -0,0 +1,26 @@
+CC = cl.exe
+LINK = link.exe
+
+# 编译和链接选项
+CFLAGS = /nologo /W3 /EHsc /Ox /DNDEBUG /I ..\TypeLibs
+LDFLAGS = /nologo Gdi32.lib user32.lib Kernel32.lib
+
+# 源文件和最终输出
+SOURCE = main.cpp cdrapp.cpp
+OBJECT = $(SOURCE:.cpp=.obj)
+TARGET = app.exe
+
+all: $(TARGET)
+
+$(TARGET): $(OBJECT)
+	$(LINK) $(LDFLAGS) /out:$(TARGET) $(OBJECT)
+
+%.obj: %.cpp
+	$(CC) $(CFLAGS) /c $<
+
+clean:
+	del /Q *.obj *.dll *.exe VGCoreAuto.tlh VGCoreAuto.tli
+
+
+##  单行命令编译
+##  cl.exe /EHsc /Ox /DNDEBUG main.cpp cdrapp.cpp /Fe:app.exe Gdi32.lib user32.lib Kernel32.lib

+ 43 - 13
cdrapp.cpp

@@ -2,20 +2,19 @@
 #include <stdio.h>
 
 #define ZERO_4PC 0, 0, 0, 0
-bool test(corel* cdr){
+
+IVGShapePtr MakeEllipse(corel* cdr, double x, double y, double r);
+IVGShapePtr MakeEllipse(corel* cdr, IVGShapePtr s, double r);
+
+IVGShapePtr MakeRectangle(corel* cdr, double x, double y, double w, double h);
+IVGShapePtr MakeRectangle(corel* cdr, IVGShapePtr s, double w, double h);
+bool polygon_gravity_dot(corel* cdr){
     cdr->ActiveDocument->Unit = cdrMillimeter;
     double x, y;
 
-//  IVGShapePtr ActiveShape;
+//  IVGShapePtr ActiveShape;    // 获取当前选中的图形 函数原型
     auto s = cdr->ActiveShape;
 
-//  建立矩形和圆形函数原型
-//  IVGShapePtr IVGLayer::CreateRectangle2 ( double x, double y, double Width, double Height, 
-//                      double RadiusUL, double RadiusUR, double RadiusLR, double RadiusLL );
-
-//  IVGShapePtr IVGLayer::CreateEllipse2 ( double CenterX, double CenterY, double Radius1, 
-//                   double Radius2, double StartAngle, double EndAngle, VARIANT_BOOL Pie );
-
 //  获取节点函数原型
 //  IVGNodePtr IVGNodes::GetItem ( long Index );
 //  IVGNodePtr IVGNodeRange::GetItem ( long Index );
@@ -27,16 +26,47 @@ bool test(corel* cdr){
         y = n->PositionY;
         printf("%f, %f\n", x, y);
 
-        auto sy = cdr->ActiveLayer->CreateEllipse2(x, y, 5, ZERO_4PC); 
+        auto sy = MakeEllipse(cdr, x, y, 5); 
         sy->Outline->Color->RGBAssign(255, 0, 0);
 
-        auto sj = cdr->ActiveLayer->CreateRectangle2(x, y, 10, 10, ZERO_4PC); 
+        auto sj = MakeRectangle(cdr, x, y, 10, 10); 
         sj->Outline->Color->RGBAssign(0, 255, 0);
-        sj->PutCenterX(x);
-        sj->PutCenterY(y);
 
     }
 
     return true;
 }
 
+//  建立矩形和圆形函数原型
+//  IVGShapePtr IVGLayer::CreateRectangle2 ( double x, double y, double Width, double Height, 
+//                      double RadiusUL, double RadiusUR, double RadiusLR, double RadiusLL );
+
+//  IVGShapePtr IVGLayer::CreateEllipse2 ( double CenterX, double CenterY, double Radius1, 
+//                   double Radius2, double StartAngle, double EndAngle, VARIANT_BOOL Pie );
+IVGShapePtr MakeEllipse(corel* cdr, double x, double y, double r){
+    return  cdr->ActiveLayer->CreateEllipse2(x, y, r, ZERO_4PC); 
+}
+
+IVGShapePtr MakeEllipse(corel* cdr, IVGShapePtr s, double r){
+    double x, y;
+    x = s->CenterX;  
+    y = s->CenterY;
+    return  cdr->ActiveLayer->CreateEllipse2(x, y, r, ZERO_4PC);   
+}
+
+IVGShapePtr MakeRectangle(corel* cdr, double x, double y, double w, double h){
+    auto sj = cdr->ActiveLayer->CreateRectangle2(x, y, w, h, ZERO_4PC); 
+    sj->PutCenterX(x);
+    sj->PutCenterY(y);
+    return  sj;
+}
+
+IVGShapePtr MakeRectangle(corel* cdr, IVGShapePtr s, double w, double h){
+    double x, y;
+    x = s->CenterX;  
+    y = s->CenterY;
+    auto sj = cdr->ActiveLayer->CreateRectangle2(x, y, w, h, ZERO_4PC); 
+    sj->PutCenterX(x);
+    sj->PutCenterY(y);
+    return  sj;
+}

+ 1 - 1
cdrapp.h

@@ -10,6 +10,6 @@ using namespace VGCore;
 void Call_CorelDRAW();
 
 
-bool test(corel* cdr);
+bool polygon_gravity_dot(corel* cdr);
 
 #endif // CDRAPP_H_INCLUDED

+ 4 - 2
main.cpp

@@ -23,7 +23,9 @@ void Call_CorelDRAW() {
 
   cdr = app;
 
-  //  调用CDR功能
-  test(cdr);
+  //  调用CDR功能, 计算多边形重心点
+
+
+  polygon_gravity_dot(cdr);
 
 }