Click here to Skip to main content
15,896,606 members
Articles / Desktop Programming / MFC

CDiagramEditor - DIY vector and dialog editor

Rate me:
Please Sign up or sign in to vote.
4.96/5 (165 votes)
23 Jun 2006Public Domain11 min read 513.3K   36.8K   302  
A feature rich vector editor skeleton.
<html>
<head>
<style>
body{font-size: 10pt;color: black;font-family: Verdana, Helvetica, Arial, sans-serif;background-color: #ffffff}
p{font-size: 10pt;color: black;font-family: Verdana, Helvetica, Arial, sans-serif;}
h2{font-size: 13pt;color: #ff9900;font-family: Verdana, Helvetica, Arial, sans-serif;font-weight: bold;}
h3{color: #ff9900;font-weight: bold;font-size: 11pt;font-family: Arial, sans-serif;}
table{background-color:#f0f0ff;}
td{font-size: 10pt;color: black;font-family: Verdana, Helvetica, Arial, sans-serif;padding:4px;}
pre{padding-right: 7pt;padding-left: 7pt;padding-bottom: 7pt;font: 9pt 'Courier New', Courier, mono;width: 100%;padding-top: 7pt;white-space: pre;background-color: #fbedbb}
code{color: #990000;font-family: 'Courier New', Courier, mono;}
A:link{text-decoration: none}
A:visited{text-decoration: none}
A:active{text-decoration: underline}
A:hover{text-decoration: underline}
A.top:link{font-size:8pt;color:red;font-family:Verdana,Helvetica,Arial,sans-serif;}
A.top:visited{font-size:8pt;color:red;font-family:Verdana,Helvetica,Arial,sans-serif;}
A.top:active{font-size:8pt;color:red;font-family:Verdana,Helvetica,Arial,sans-serif;}
A.top:hoover{font-size:8pt;color:red;font-family:Verdana,Helvetica,Arial,sans-serif;}
</style>
</head>
<body>
<h2>CDiagramLine</h2><h3>Overview</h3>
<blockquote>
<b>Purpose</b><br>
Encapsulates a line object. Other line objects can be derived from this class.<br>
<p><b>Description</b><br>
First of all, we do not want constraints to the line size (as we can't move the end points freely if that is the case), so one <code>SetRect</code> must be modified. Second, we need a non-rectangular body area for hit testing, a line in this case. Third, we need only a subset of the selection markers. All this is implemented in this class, to serve as a model or base class for other line objects.<br>
<p><b>Usage</b><br>
Use as a model for line objects.
<p><a class='top' href='index.html'>[back to the index page]</a>
</blockquote>
<a name='contents'></a><h3>Contents</h3>
<b>- B -</b><br>
<a href='#BodyInRectCRectrectconst'>BodyInRect( CRect rect ) const</a><br>
<p>
<b>- C -</b><br>
<a href='#CDiagramLine'>CDiagramLine()</a><br>
<a href='#Clone'>Clone()</a><br>
<a href='#CreateFromStringconstCStringstr'>CreateFromString( const CString& str )</a><br>
<p>
<b>- D -</b><br>
<a href='#DrawCDCdcCRectrect'>Draw( CDC* dc, CRect rect )</a><br>
<a href='#DrawSelectionMarkersCDCdcCRectrectconst'>DrawSelectionMarkers( CDC* dc, CRect rect ) const</a><br>
<p>
<b>- G -</b><br>
<a href='#GetCursorinthitconst'>GetCursor( int hit ) const</a><br>
<a href='#GetHitCodeCPointpointconst'>GetHitCode( CPoint point ) const</a><br>
<p>
<b>- S -</b><br>
<a href='#SetRectCRectrect'>SetRect( CRect rect )</a><br>
<p>
<b>- ~ -</b><br>
<a href='#~CDiagramLine'>~CDiagramLine()</a><br>
<p><h3>Functions</h3><hr>
<code><b><a name='BodyInRectCRectrectconst'></a>BOOL BodyInRect( CRect rect ) const</b></code>
<blockquote>
<b>Description</b><br>
Checks if some part of the body of this object lies inside the rectangle <code>rect</code>.
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
<code>CRect rect </code> -  The rectangle to test.<br>
<b>Returns</b><br>
<code>BOOL  </code> -  <code>TRUE</code> if any part of the object lies inside rect.
<br><br><b>Usage</b><br>
Shows one way to test a non-rectangular object body - in this case a line.<p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<code><b><a name='CDiagramLine'></a>CDiagramLine()</b></code>
<blockquote>
<b>Description</b><br>
Constructor
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
none<br>
<b>Returns</b><br>
void
<br><br><b>Usage</b><br>
-<p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<code><b><a name='Clone'></a>CDiagramEntity* Clone()</b></code>
<blockquote>
<b>Description</b><br>
Clones this object and returns a new one.
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
none<br>
<b>Returns</b><br>
<code>CDiagramEntity* </code> -  The resulting clone
<br><br><b>Usage</b><br>
Call to clone the current object.<p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<code><b><a name='CreateFromStringconstCStringstr'></a>CDiagramEntity* CreateFromString( const CString& str )</b></code>
<blockquote>
<b>Description</b><br>
Static factory function to create a <code>CDiagramLine</code> object from <code>str</code>.
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
<code>const CString& str </code> -  String representation to decode.<br>
<b>Returns</b><br>
<code>CDiagramEntity*  </code> -  Resulting object, <code>NULL</code> if <code>str</code> is not a representation of a <code>CDiagramLine</code>.
<br><br><b>Usage</b><br>
One proposed mechanism for loading/creating <code>CDiagramEntity</code>-derived objects from a text stream.<p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<code><b><a name='DrawCDCdcCRectrect'></a>void Draw( CDC* dc, CRect rect )</b></code>
<blockquote>
<b>Description</b><br>
Draws the object.
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
<code>CDC* dc  </code> -  <code>CDC</code> to draw to<br><code>CRect rect </code> -  True (zoomed) rectangle to draw to.<br>
<b>Returns</b><br>
void
<br><br><b>Usage</b><br>
Called from <code>CDiagramEditor::DrawObjects</code>.<p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<code><b><a name='DrawSelectionMarkersCDCdcCRectrectconst'></a>void DrawSelectionMarkers( CDC* dc, CRect rect ) const</b></code>
<blockquote>
<b>Description</b><br>
Draws selection markers for this object.
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
<code>CDC* dc  </code> -  <code>CDC</code> to draw to.<br><code>CRect rect </code> -  True object rectangle.<br>
<b>Returns</b><br>
void
<br><br><b>Usage</b><br>
Draws a subset of the standard selection markers.<p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<code><b><a name='GetCursorinthitconst'></a>HCURSOR GetCursor( int hit ) const</b></code>
<blockquote>
<b>Description</b><br>
Returns the cursor for a specific hit point.
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
<code>int hit </code> -  The hit point constant (<code>DEHT_</code>, defined in DiagramEntity.h) to show a cursor for.<br>
<b>Returns</b><br>
<code>HCURSOR </code> -  The cursor to display, or <code>NULL</code> if default.
<br><br><b>Usage</b><br>
Shows the cursor for a subset of the hit points. Will also show cursors different from the standard ones. <code>hit</code> can be one of the following: <p><table width='100%'><tr><td><code>DEHT_NONE</code></td><td>No hit-point </td></tr><tr><td><code>DEHT_BODY</code></td><td>Inside object body </td></tr><tr><td><code>DEHT_TOPLEFT</code></td><td>Top-left corner </td></tr><tr><td><code>DEHT_TOPMIDDLE</code></td><td>Middle top-side </td></tr><tr><td><code>DEHT_TOPRIGHT</code></td><td>Top-right corner </td></tr><tr><td><code>DEHT_BOTTOMLEFT</code></td><td>Bottom-left corner </td></tr><tr><td><code>DEHT_BOTTOMMIDDLE</code></td><td>Middle bottom-side </td></tr><tr><td><code>DEHT_BOTTOMRIGHT</code></td><td>Bottom-right corner </td></tr><tr><td><code>DEHT_LEFTMIDDLE</code></td><td>Middle left-side </td></tr><tr><td><code>DEHT_RIGHTMIDDLE</code></td><td>Middle right-side</td></tr></table><p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<code><b><a name='GetHitCodeCPointpointconst'></a>int GetHitCode( CPoint point ) const</b></code>
<blockquote>
<b>Description</b><br>
Returns the hit point constant (<code>DEHT_</code>, defined in DiagramEntity.h) for point.
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
<code>CPoint point </code> -  The point to test.<br>
<b>Returns</b><br>
<code>int    </code> -  The resulting hit point constant, <code>DEHT_NONE</code> if none.
<br><br><b>Usage</b><br>
Shows one way to hit point test a non- rectangular area. The hit point can be one of the following: <p><table width='100%'><tr><td><code>DEHT_NONE</code></td><td>No hit-point </td></tr><tr><td><code>DEHT_BODY</code></td><td>Inside object body </td></tr><tr><td><code>DEHT_TOPLEFT</code></td><td>Top-left corner </td></tr><tr><td><code>DEHT_TOPMIDDLE</code></td><td>Middle top-side </td></tr><tr><td><code>DEHT_TOPRIGHT</code></td><td>Top-right corner </td></tr><tr><td><code>DEHT_BOTTOMLEFT</code></td><td>Bottom-left corner </td></tr><tr><td><code>DEHT_BOTTOMMIDDLE</code></td><td>Middle bottom-side </td></tr><tr><td><code>DEHT_BOTTOMRIGHT</code></td><td>Bottom-right corner </td></tr><tr><td><code>DEHT_LEFTMIDDLE</code></td><td>Middle left-side </td></tr><tr><td><code>DEHT_RIGHTMIDDLE</code></td><td>Middle right-side</td></tr></table><p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<code><b><a name='SetRectCRectrect'></a>void SetRect( CRect rect )</b></code>
<blockquote>
<b>Description</b><br>
Sets the rectangle of the object.
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
<code>CRect rect </code> -  New rectangle<br>
<b>Returns</b><br>
void
<br><br><b>Usage</b><br>
Overriden to avoid normalization.<p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<code><b><a name='~CDiagramLine'></a>~CDiagramLine()</b></code>
<blockquote>
<b>Description</b><br>
Destructor
<br><b>Access</b><br>
Public
<br><br><b>Parameters</b><br>
none<br>
<b>Returns</b><br>
void
<br><br><b>Usage</b><br>
-<p>
<a class='top' href='#contents'>[back to the contents]</a>&nbsp;<a class='top' href='index.html'>[back to the index page]</a></p>
</blockquote>
<hr>
<b><small>Copyright 2004 Johan Rosengren Abstrakt Mekanik AB</small></b>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Software Developer (Senior) Abstrakt Mekanik AB
Sweden Sweden
45 years old, married, three kids.

Started with computers more than 20 years ago on a CBM-64.

Read Theoretical Philosophy at the University of Lund.

Working as a C++ consultant developer.

Science-fiction freak. Enjoy vintage punkrock.

Comments and Discussions