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

An MFC Chart Control with Enhanced User Interface

Rate me:
Please Sign up or sign in to vote.
4.92/5 (102 votes)
17 Jun 2013CPOL112 min read 442K   98.8K   390  
An MFC linear chart control with enhanced appearance.
///////////////////////////////////////////////////////////////////////////////
//
//  Util.cpp
//
///////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "util.h"

using namespace Gdiplus;

///////////////////////////////////////////////////////////////////////////////
// Normalize string len

string_t NormalizeString(string_t str, size_t maxLen, TCHAR delim)
{
  size_t strLen = str.length();
  if (strLen > maxLen)
  {
    size_t position = maxLen - 2;
    str[position++] = delim;
    str[position++] = str[strLen - 1];
    str.erase(position, strLen);
  }
  return str;
}


///////////////////////////////////////////////////////////////////////////////
// Create rounded rect

void CreateRoundedRect(GraphicsPath& grPath, RectF& rectF, float radius, bool bReset)
{
  if (bReset)
    grPath.Reset();

  float d = radius * 2.0f;

  PointF pt1(rectF.X + radius, rectF.Y);                // Left end of top straight line
  PointF pt2(rectF.X + rectF.Width - radius, rectF.Y);  // Right end of top straight line  
  RectF r1(rectF.X, rectF.Y, d, d);                     // Left top arc bounding rect

  grPath.AddArc(r1, 180, 90);                           // Left top arc
  grPath.AddLine(pt1, pt2);                             // Top straight line

  SizeF sizeRectF;
  rectF.GetSize(&sizeRectF);                            // Get offset's base

  r1.Offset(sizeRectF.Width - d, 0);                    // Right top arc bounding rect
  grPath.AddArc(r1, 270, 90);                           // Right top arc
  
  pt1 = PointF(rectF.GetRight(), rectF.GetTop() + radius);    // Top end of right down line
  pt2 = PointF(rectF.GetRight(), rectF.GetBottom() - radius); // Bottom end
  grPath.AddLine(pt1, pt2);                             // Right line from top to bottom

  r1.Offset(0, sizeRectF.Height - d);                   // Move to the right bottom corner
  grPath.AddArc(r1, 0, 90);                             // Right bottom arc

  pt1 = PointF(rectF.GetRight() - radius, rectF.GetBottom());
  pt2 = PointF(rectF.GetLeft() + radius, rectF.GetBottom());
  grPath.AddLine(pt1, pt2);

  r1.Offset(-sizeRectF.Width + d,0);
  grPath.AddArc(r1, 90, 90);

  pt1 = PointF(rectF.GetLeft(), rectF.GetBottom() - radius);
  pt2 = PointF(rectF.GetLeft(), rectF.GetTop() + radius);
  grPath.AddLine(pt1, pt2);
}

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 The Code Project Open License (CPOL)


Written By
Software Developer Verizon Internet Services
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions