Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

The Ultimate Toolbox Graphics Classes

0.00/5 (No votes)
25 Aug 2007 1  
Ultimate Toolbox classes that help with DIBs, MetaFiles, and more.

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Contents

Introduction

The Ultimate Toolbox contains several classes that enable the integration of graphic-based routines in your MFC based application.

Device Independent Bitmaps

COXDIB is an MFC extension encapsulating DIB operations. It includes functionality for reading/writing BMP and JPG files, conversion, palette extraction, resizing, rotation (at 90�increments), dithering, and drawing. Many of the Ultimate Toolbox classes make use of this class for graphics file rendering.

As an example, consider the rendering of a large 24 bit per pixel bitmap in a small area on a 256 color display. The best approach is to resize, dither, then render the resulting dib:

...
m_DIB.Read("c:\some.bmp");
m_DIB.ResizeDIB(320, 200);
m_DIB.HalfToneDitherDIB();
...
m_PeriDIB.Paint(pDC, CRect(0, 0, 320, 200), CRect(0, 0, 320, 200));
...

Graphics

COXGraphics class was designed in order to provide advanced graphics routines for programmers. It is currently used internally in the COXRoundedButton class to render the button.

void COXRoundedButton::DrawButtonBackground(CDC* pDC, CRect buttonRect, 
    UINT nState, CPalette* pPalette/*=NULL*/)
{
    // back color, may be used as transparent color


    COLORREF BackColor=m_clrBk;

    CSize szRadius=CalcSphereRadius();

    COXGraphics graphics;

    if (!(IsChecked() || (nState & ODS_SELECTED) == ODS_SELECTED))
    {
        graphics.DrawRoundedButton(pDC,buttonRect.left,buttonRect.top,
            buttonRect.Width(),buttonRect.Height(),
            szRadius.cx,szRadius.cy,pPalette,
            m_clrButton,m_clrLight,m_fThetta, 
            m_fPhi,m_fLightIntensityCoef,
            m_nPhong,m_fMirror,m_fDiffuse,
            m_fAmbient,BackColor);
    }
    else
    {
        graphics.DrawRoundedButton(pDC,buttonRect.left,buttonRect.top,
            buttonRect.Width(),buttonRect.Height(),
            szRadius.cx,szRadius.cy+(szRadius.cx-szRadius.cy)/3,pPalette,
            m_clrButton,m_clrLight,m_fThetta, 
            m_fPhi+180,m_fLightIntensityCoef,
            m_nPhong,0,m_fDiffuse,
            m_fAmbient,BackColor);
    }
}

Image Viewer

The COXImageViewer class is a COXScrollWnd based class which is designed to display DIB (bitmap) and (optionally) JPEG images.


The samples\graphics\ImageViewer sample in action.

Meta Files

COXMetaFile supports Windows 3.x, Aldus header and enhanced metafiles (*.wmf and *.emf).


A metafile as displayed in the samples/graphics/metafile example.
void CMetaFileView::OnDraw(CDC* pDC)
{
    CMetaFileDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);

    // TODO: add draw code for native data here


    CRect rectClient;
    GetClientRect( &rectClient);
    if (m_bMaintainRatio)
    {    
        if (! pDoc->m_MetaFile.PlayFile (pDC, &rectClient) )
            AfxMessageBox (_T("Error in COXMetaFile::PlayFile"));
    }
    else
    {    
        if (! pDoc->m_MetaFile.PlayFile (pDC ) )
            AfxMessageBox (_T("Error in COXMetaFile::PlayFile"));
    }
    return ;
}

Shaped Splash Window

COXSplashWnd and COXSplashWndDIB allow for quick and easy implementation of customizable splash windows.

The LoadBitmap method of COXSplashWndDib can specify a border color (default is 0xFF000000) that will be made transparent, giving the appearance of a shaped window. Each outer pixel in this color will be made invisible.

COXSplashWnd can be seen in action in the samples\graphics\Splash example.

History

Initial CodeProject release August 2007.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here