123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- #include "cdrapp.h"
- #include <stdio.h>
- #define _USE_MATH_DEFINES
- #include <math.h> // C++ 在 math.h 中定义 M_PI 需要 _USE_MATH_DEFINES 宏
- bool Test_Intersect(corel* cdr){
- cdr->ActiveDocument->Unit = cdrInch;
- IVGShapePtr s[3];
- IVGShapePtr si[3];
- IVGShapePtr sm;
- double x, y, radius = 1.5 ;
- int r, g, b;
- // 通过将 i 乘以 2.09439507 (120度的弧度),可以将三个椭圆均匀地分布在一个圆上。
- // radius = 1.5 则是决定椭圆的大小。 这个数字控制椭圆的半径,也就是椭圆的大小。 // 创建3个椭圆, 填色 RGB:
- for (int i = 0; i != 3; i++) {
- x = cdr->ActivePage->SizeWidth / 2 + 1 * cos(i * M_PI * 2.0 / 3.0);
- y = cdr->ActivePage->SizeHeight / 2 + 1 * sin(i * M_PI * 2.0 / 3.0);
- s[i] = MakeEllipse(cdr, x, y, radius);
- r = 255 * (i == 0);
- g = 255 * (i == 1);
- b = 255 * (i == 2);
- s[i]->Fill->UniformColor->RGBAssign(r, g, b);
- }
- // 创建3个相交物件, IVGShape::Intersect 函数原型
- // IVGShapePtr IVGShape::Intersect ( struct IVGShape * TargetShape, VARIANT_BOOL LeaveSource, VARIANT_BOOL LeaveTarget );
- for (int i = 0; i != 3; i++) {
- int n = (i + 1) % 3;
- si[i] = s[i]->Intersect(s[n], true, true);
- auto c1 = s[i]->Fill->UniformColor;
- auto c2 = s[n]->Fill->UniformColor;
- r = c1->RGBRed + c2->RGBRed;
- g = c1->RGBGreen + c2->RGBGreen;
- b = c1->RGBBlue + c2->RGBBlue;
- si[i]->Fill->UniformColor->RGBAssign(r, g, b);
- }
- // 建立相交物件,填充白色
- sm = si[1]->Intersect(si[2], true, true);
- auto c3 = cdr->CreateRGBColor(255, 255, 255);
- sm->Fill->UniformColor = c3;
- return true;
- }
- bool polygon_gravity_dot(corel* cdr){
- cdr->ActiveDocument->Unit = cdrMillimeter;
- double x, y;
- // IVGShapePtr ActiveShape; // 获取当前选中的图形 函数原型
- auto s = cdr->ActiveShape;
- // IVGShapeRangePtr IVGApplication::CreateShapeRange ( );
- auto srs = cdr->CreateShapeRange();
- // 获取节点函数原型
- // IVGNodePtr IVGNodes::GetItem ( long Index );
- // IVGNodePtr IVGNodeRange::GetItem ( long Index );
- for(auto i = 0; i < s->DisplayCurve->Nodes->Count; i++){
- auto n = s->DisplayCurve->Nodes->Item[i+1];
- x = n->PositionX;
- y = n->PositionY;
- printf("%f, %f\n", x, y);
- // auto sy = MakeEllipse(cdr, x, y, 5);
- // sy->Outline->Color->RGBAssign(255, 0, 0);
- // auto sj = MakeRectangle(cdr, x, y, 10, 10);
- // sj->Outline->Color->RGBAssign(0, 255, 0);
- auto l = DrawLine(cdr, x, y, s->CenterX, s->CenterY);
- srs->Add(l);
- }
- // HRESULT IVGShapeRange::CreateSelection ( );
- srs->CreateSelection();
- 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;
- }
- // IVGShapePtr IVGLayer::CreateLineSegment ( double StartX, double StartY, double EndX, double EndY );
- // 画一条线,设置轮廓色 M100
- IVGShapePtr DrawLine(corel* cdr, double x1, double y1, double x2, double y2){
- auto line = cdr->ActiveLayer->CreateLineSegment(x1, y1, x2, y2);
- line->Outline->Color->CMYKAssign(0, 100, 0, 0);
- return line;
- }
- // IVGShapePtr IVGLayer::FindShape ( _bstr_t Name, enum cdrShapeType Type, long StaticID, VARIANT_BOOL Recursive );
- // IVGShapePtr IVGLayer::CreateCurveSegment ( double StartX, double StartY, double EndX, double EndY, double StartingControlPointLength,
- // double StartingControlPointAngle, double EndingControlPointLength, double EndingControlPointAngle );
- // IVGShapePtr IVGLayer::CreateCurveSegment2 ( double x1, double y1, double StartingControlPointX, double StartingControlPointY,
- // double EndingControlPointX, double EndingControlPointY, double x2, double y2 );
|