home *** CD-ROM | disk | FTP | other *** search
- //******************************************************************'
- //* *'
- //* TurboCAD for Windows *'
- //* Copyright (c) 1993 - 2004 *'
- //* International Microcomputer Software, Inc. *'
- //* (IMSI) *'
- //* All rights reserved. *'
- //* *'
- //******************************************************************'
- using System;
- using System.Reflection;
-
- namespace CSharpRoundRect
- {
- /// <summary>
- /// Summary description for Class1.
- /// </summary>
- public class CSharpRoundRect
- {
- const int gkGraphic = 11;
- const int gkArc = 2;
- const int gkText = 6;
- const int gfCosmetic = 128;
-
- //Useful math constants
- const double PI = 3.1415926500000002;
-
- //'Real variant types!
- const int typeEmpty = 0;
- const int typeInteger = 2;
- const int typeLong = 3;
- const int typeSingle = 4;
- const int typeDouble = 5;
- const int typeCurrency = 6;
- const int typeDate = 7;
- const int typeString = 8;
- const int typeObject = 9;
- const int typeBoolean = 11;
- const int typeVariant = 12;
- const int typeIntegerEnum = typeInteger + 100;
- const int typeLongEnum = typeLong + 100;
- const int typeStringEnum = typeString + 100;
-
- //'Stock property pages
- const int ppStockPen = 1;
- const int ppStockBrush = 2;
- const int ppStockText = 4;
- const int ppStockInsert = 8;
- const int ppStockViewport = 16;
- const int ppStockAuto = 32;
-
- //'Property Ids
- const int idRoundness = 1;
- const int idBeginColor = 2;
- const int idEndColor = 3;
- const int idGradientMode = 4;
-
- //'Property enums
-
- //'Number of properties, pages, wizards
- const int NUM_PROPERTIES = 1;
- const int NUM_PAGES= 1;
- const int NUM_WIZARDS = 0;
- frmRRect m_RRectPropertyPage;
-
- public CSharpRoundRect()
- {
- m_RRectPropertyPage = new frmRRect();
- }
- public string Description
- {
- get
- {
- return "SDK C# NET RoundRectangle (VB NET sample)";
- }
- }
- public int GetPropertyInfo(out object Names, out object Types, out object IDs, out object Defaults)
- {
-
- int retVal;
- string[] strNames = new string[NUM_PROPERTIES];
- int[] intTypes = new int[NUM_PROPERTIES];
- int[] intIds = new int[NUM_PROPERTIES];
- object[] dblDefaults = new object[NUM_PROPERTIES];
-
- strNames[0] = "Roundness";
- intTypes[0] = typeDouble;
- intIds[0] = idRoundness;
- dblDefaults[0] = 50;
- Names = strNames;
- Types = intTypes;
- IDs = intIds;
- Defaults = dblDefaults;
-
- retVal = NUM_PROPERTIES;
- return retVal;
- }
-
-
- public int GetPageInfo(object AGraphic, out int StockPages,out object Names)
- {
-
- string[] strNames = new string[NUM_PAGES];
- strNames[0] = m_RRectPropertyPage.Text;
- StockPages = ppStockBrush + ppStockPen + ppStockAuto;
- Names = strNames;
- return NUM_PAGES;
- }
-
-
- public int GetWizardInfo(out object Names)
- {
- string[] strNames = new string[NUM_WIZARDS];
- Names = strNames;
- return NUM_WIZARDS;
- }
-
- //Enumerate the names and values of a specified property
- public int GetEnumNames(int PropID, object Names, object Values)
- {
- return 0;
- }
-
-
- public bool PageControls(object ThisRegenMethod, IMSIGX.Graphic Graphic, int PageNumber, bool SaveProperties)
- {
- IMSIGX.Property gxProp;
- double Roundness;
- object varIndex;
- object varValue;
- try
- {
- if (SaveProperties)
- {
- //'OK button on property page was clicked
- //Form is still loaded
- ///With m_RRectPropertyPage
- //Need On Error statement for the case where you have
- //RRect Turbo Shape and ahother "shape" selected
- //On Error Resume Next
-
- //When the property page is closed, transfer the numeric
- //roundness value from the TextBox to the Graphic
- //Get the value as a double-precision number
- Roundness = System.Convert.ToDouble(m_RRectPropertyPage.tbRoundness.Text);
- /*
- mBeginColor = .cmColor1.BackColor
- mEndColor = .cmColor2.BackColor
- mGradientMode = .cModesCombo.SelectedIndex
- */
- //'Make sure it's between 0 and 100
- if (Roundness < 0.0)
- {
- Roundness = 0.0;
- }
- if (Roundness > 100.0)
- {
- Roundness = 100.0;
- }
- //'Set the roundness property value in the Graphic
- varIndex = "Roundness";
- gxProp = Graphic.Properties.get_Item(ref varIndex);
- varValue = Roundness;
- gxProp.set_Value(0,ref varValue );
- }
- else
- {
- //'Property page is about to be opened
- //'Make sure the form is loaded
- //'If more than one RRect is selected and they do not
- //'have the same properties, don't set up this field
- //'When the property page is opening, transfer the numeric
- //'roundness value from the Graphic to the TextBox
- //'Get the roundness property value from the Graphic
- varIndex = "Roundness";
- gxProp = Graphic.Properties.get_Item(ref varIndex);
- // Roundness = (double)gxProp.get_Value(0);
- Roundness = System.Convert.ToDouble (gxProp.get_Value(0));
- //'Set the TextBox control's text
- m_RRectPropertyPage.tbRoundness.Text = System.Convert.ToString (Roundness);
- }
- return true;
- }
- catch
- {
- return false;
- }
- }
-
- public void PageDone(object ThisRegenMethod, int PageNumber)
- {
- }
- public bool PropertyPages(object ThisRegenMethod, int PageNumber)
- {
- bool bRet;
- m_RRectPropertyPage.ShowDialog();
- bRet = !m_RRectPropertyPage.bCanceled;
- return bRet;
- }
- public bool Wizard(object ThisRegenMethod, int WizardNumber)
- {
- return false;
- }
- public void OnGeometryChanged(object Graphic, long GeomID, object paramOld, object paramNew)
- {
- //'Do nothing
- //'Regen Graphic
- }
-
- //'Called when vertex is moved, or other geometry change
- public bool OnGeometryChanging(object Graphic, int GeomID, object paramOld, object paramNew)
- {
- //'OK to continue with change
- return true;
- }
-
- public bool OnNewGraphic(IMSIGX.Graphic grfThis, bool boolCopy)
- {
- if (boolCopy)
- {
- //'Vertices are already added for us...
- return true;
- }
- object missing = Missing.Value;
-
- object varTrue;
- object varFalse;
- object varX;
- object varY;
- object varZ;
- object varIndex;
- object varValue;
- varTrue = true;
- varFalse = false;
- try
- {
-
- // On Error GoTo Failed
- // 'New Graphic being created
- // 'X, Y, Z, PenDown, Selectable, Snappable, Editable, Linkable
- // 'First Vertex is "lower left" corner
- varX = -1.0;
- varY = -0.5;
- varZ = 0;
- grfThis.Vertices.Add (ref varX, ref varY, ref varZ, ref varFalse, ref varTrue, ref varFalse, ref varFalse, ref varFalse,ref varFalse,ref missing, ref missing) ;
- //'Second Vertex is "upper right" corner
- varX = 1.0;
- varY = 0.5;
- varZ = 0;
- grfThis.Vertices.Add (ref varX, ref varY, ref varZ, ref varFalse, ref varTrue, ref varFalse, ref varFalse, ref varFalse,ref varFalse,ref missing, ref missing) ;
- //'Third Vertex is rounding handle (calculated)
- double R,Roundness, Offset;
- IMSIGX.Property P;
- varIndex = "Roundness";
- P = grfThis.Properties.get_Item(ref varIndex);
- // Roundness = (double)P.get_Value(0);
- Roundness = System.Convert.ToDouble (P.get_Value(0));
-
- R = 0.5 * Roundness / 100.0;
- Offset = 0.10000000000000001 * R;
- varX = 1.0 - R;
- varY = 0.5 + Offset;
- varZ = 0;
-
- grfThis.Vertices.Add (ref varX, ref varY, ref varZ, ref varFalse, ref varFalse, ref varFalse, ref varFalse, ref varFalse,ref varFalse,ref missing, ref missing) ;
- //'Fourth Vertex is rounding handle (editable)
- grfThis.Vertices.Add (ref varX, ref varY, ref varZ, ref varFalse, ref varTrue, ref varFalse, ref varTrue, ref varFalse,ref varFalse,ref missing, ref missing) ;
- varIndex = "LimitVertices";
- P = grfThis.Properties.get_Item(ref varIndex);
- varValue = 4;
- P.set_Value(0, ref varValue);
- //OnNewGraphic = true
- return true;
- }
- catch(Exception e)
- {
-
- //'Return false on failure
- Console.WriteLine("An error occurred: '{0}'", e);
-
- return false;
- }
- }
-
-
- //'Function called whenever a copy of a graphic is being made
- public bool OnCopyGraphic(object grfCopy, object grfSource)
- {
- //'Return false on failure
- return true;
- }
-
- //'Notification function called after graphic property is saved
- public void OnPropertyChanged(object Graphic,int PropID, object ValueOld, object ValueNew)
- {
- //'Do nothing
- }
-
- //'Notification function called when graphic property is saved
- public bool OnPropertyChanging(object Graphic, int PropID, object ValueOld, object ValueNew)
- {
- //'OK to proceed
- // OnPropertyChanging = True
- return true;
- }
-
- //'Notification function called when graphic property is retrieved
- public void OnPropertyGet(object Graphic, int PropID)
- {
- //'Do nothing
- }
-
-
- public void Regen(IMSIGX.Graphic grfThis)
- {
- //'Setup error handler
- object missing = Missing.Value;
- object varIndex;
- object varValue;
- object varX;
- object varY;
- object varZ;
- object varTrue;
- object varFalse;
- object varType;
- varTrue = true;
- varFalse = false;
-
- IMSIGX.IVertex gxVrt, gxVrt1;
- IMSIGX.Property P ;
-
- // 'Set up lock (prevent recursion)
- try
- {
- int LockCount;
- LockCount = grfThis.RegenLock();
- //'Setup error handler (make sure lock is removed)
- //On Error GoTo FailedLock
- if (LockCount == 0)
- {
- //'Delete any previous cosmetic children
- varValue = gfCosmetic;
- grfThis.Graphics.Clear(ref varValue);
- bool boolHandleMoved;
- //'Calculate height, width and radius of corners
- double W, H, R, Roundness;
- IMSIGX.Vertices pVerts;
- pVerts = grfThis.Vertices;
-
- varIndex = 2;
- gxVrt = pVerts.get_Item(ref varIndex);
- varIndex = 3;
- gxVrt1 = pVerts.get_Item(ref varIndex);
-
-
- if (Math.Abs(gxVrt.X - gxVrt1.X) < 0.00000099999999999999995 && Math.Abs(gxVrt.Y - gxVrt1.Y) < 0.00000099999999999999995)
- {
- boolHandleMoved = false;
- }
- else
- {
- boolHandleMoved = true;
- }
- varIndex = 1;
- gxVrt = pVerts.get_Item(ref varIndex);
- varIndex = 0;
- gxVrt1 = pVerts.get_Item(ref varIndex);
-
- W = Math.Abs(gxVrt.X - gxVrt1.X);
- H = Math.Abs(gxVrt.Y - gxVrt1.Y);
-
- //'Radius of arcs is based on minimum of width and height
- if (W < H)
- {
- R = W / 2.0;
- }
- else
- {
- R = H / 2.0;
- }
- // 'Adjust radius for roundness
- if (boolHandleMoved)
- {
- varIndex = 2;
- gxVrt = pVerts.get_Item(ref varIndex);
- varIndex = 3;
- gxVrt1 = pVerts.get_Item(ref varIndex);
-
- Roundness = Math.Abs(gxVrt.X - gxVrt1.X);
- Roundness = Roundness * 100.0 / R;
- if (Roundness > 100.0)
- {
- Roundness = 100.0;
- }
- //'Relocate handle
-
- //'Update property to reflect handle location
- varIndex = "Roundness";
- P = grfThis.Properties.get_Item(ref varIndex);
- varValue = Roundness;
- P.set_Value(0, ref varValue);
- }
- else
- {
- varIndex = "Roundness";
- P = grfThis.Properties.get_Item(ref varIndex);
-
- // Roundness = (double)P.get_Value(0);
- Roundness = System.Convert.ToDouble (P.get_Value(0));
- if (Roundness < 0.0)
- {
- Roundness = 0.0;
- }
- if (Roundness > 100.0)
- {
- Roundness = 100.0;
- }
- }
- R = R * Roundness / 100.0;
- //'Add child Graphics
- IMSIGX.IGraphic grfChild;
- double X0, Y0, X1, Y1, T;
- varIndex = 0;
- gxVrt = pVerts.get_Item(ref varIndex);
- varIndex = 1;
- gxVrt1 = pVerts.get_Item(ref varIndex);
- X0 = gxVrt.X;
- Y0 = gxVrt.Y;
- X1 = gxVrt1.X;
- Y1 = gxVrt1.Y;
- //'Make sure X0 < X1
- if (X0 > X1)
- {
- T = X0;
- X0 = X1;
- X1 = T;
- }
- //'Make sure Y0 < Y1
- if (Y0 > Y1)
- {
- T = Y0;
- Y0 = Y1;
- Y1 = T;
- }
- //End With
-
- if (R == 0.0)
- {
- //'No rounded corners
- //'All children are cosmetic
- varValue = gkGraphic;
- grfChild = grfThis.Graphics.Add(ref varValue, ref missing, ref missing,ref missing,ref missing, ref missing);
- grfChild.Cosmetic = true;
- //'Now add vertices to the child
- varX = X0;
- varY = Y0;
- varZ = 0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref missing, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- varY = Y1;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref varTrue, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- varX = X1;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref varTrue, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- varY = Y0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref varTrue, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
-
- //'Close the rectangle
- // .AddClose(PenDown:=true) //'PenDown
- grfChild.Vertices.AddClose(ref varTrue, ref missing,ref missing,ref missing,ref missing,ref missing); //'PenDown
- //End With
- }
- else
- {
- //'Rounded corners
- //'We'll make 4 line children and 4 arc children
- // 'First line
- //'All children are cosmetic
- varValue = gkGraphic;
- grfChild = grfThis.Graphics.Add(ref varValue,ref missing,ref missing,ref missing,ref missing,ref missing);
- grfChild.Cosmetic = true;
- //'Now add vertices to the child
- varX = X0 + R;
- varY = Y0;
- varZ = 0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref missing, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- varX = X1 - R;
- varY = Y0;
- varZ = 0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref varTrue, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- //'First arc
- varValue = gkArc;
- grfChild = grfThis.Graphics.Add(ref varValue, ref missing,ref missing,ref missing,ref missing,ref missing);
- grfChild.Cosmetic = true;
-
- varX = X1 - R;
- varY = Y0 + R;
- varZ = 0;
- object varR;
- object varRot;
- varRot = 0;
- varR = R;
- varValue = 1.5 * PI;
- grfChild.ArcSet(ref varX, ref varY, ref varZ, ref varR, ref missing, ref varValue, ref varRot, ref missing);
- //'Second line
- varValue = gkGraphic;
- grfChild = grfThis.Graphics.Add(ref varValue, ref missing,ref missing,ref missing,ref missing,ref missing);
- grfChild.Cosmetic = true;
- //With grfChild.Vertices
- varX = X1;
- varY = Y0 + R;
- varZ = 0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref missing, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- varX = X1;
- varY = Y1 - R;
- varZ = 0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref varTrue, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- //'Second arc
- varValue = gkArc;
- grfChild = grfThis.Graphics.Add(ref varValue,ref missing,ref missing,ref missing,ref missing,ref missing);
- grfChild.Cosmetic = true;
- varX = X1 - R;
- varY = Y1 - R;
- varZ = 0;
- varRot = 0;
- varR = R;
- varValue = 0.5 * PI;
- grfChild.ArcSet(ref varX, ref varY, ref varZ, ref varR, ref missing, ref varRot, ref varValue, ref missing);
- //'Third line
- varValue = gkGraphic;
- grfChild = grfThis.Graphics.Add(ref varValue, ref missing, ref missing, ref missing,ref missing,ref missing);
- grfChild.Cosmetic = true;
- varX = X1 - R;
- varY = Y1;
- varZ = 0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref missing, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- varX = X0 + R;
- varY = Y1;
- varZ = 0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref varTrue, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- //'Third arc
- varValue = gkArc;
- grfChild = grfThis.Graphics.Add(ref varValue,ref missing, ref missing,ref missing,ref missing,ref missing);
- grfChild.Cosmetic = true;
-
- varX = X0 + R;
- varY = Y1 - R;
- varZ = 0;
- varRot = 0;
- varR = R;
- varValue = 0.5 * PI;
- object varPI;
- varPI = PI;
- grfChild.ArcSet(ref varX, ref varY, ref varZ, ref varR, ref missing, ref varValue, ref varPI, ref missing);
- //'Fourth line
- varType = gkGraphic;
- grfChild = grfThis.Graphics.Add(ref varType, ref missing, ref missing,ref missing,ref missing,ref missing);
- grfChild.Cosmetic = true;
- varX = X0;
- varY = Y1 - R;
- varZ = 0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref missing, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- varX = X0;
- varY = Y0 + R;
- varZ = 0;
- grfChild.Vertices.Add(ref varX, ref varY, ref varZ, ref varTrue, ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);
- //'Fourth arc
- varType = gkArc;
- grfChild = grfThis.Graphics.Add(ref varType, ref missing, ref missing,ref missing, ref missing,ref missing);
- grfChild.Cosmetic = true;
-
- varX = X0 + R;
- varY = Y0 + R;
- varZ = 0;
- varRot = 0;
- varR = R;
- varValue = 1.5 * PI;
- varPI = PI;
- grfChild.ArcSet(ref varX, ref varY, ref varZ, ref varR, ref missing, ref varPI, ref varValue, ref missing);
- }
-
- //'Add visible child Graphics
- }
-
- grfThis.RegenUnlock(ref missing);
- }
-
- catch
- {
- grfThis.RegenUnlock(ref missing);
- }
- }
-
-
- public bool Draw(object grfThis, object view, object mat)
- {
- return false;
- }
-
- }
-
- }
-
-