Click here to Skip to main content
15,881,559 members
Articles / Desktop Programming / MFC

Be Sweet - a set of visual source code browsers

Rate me:
Please Sign up or sign in to vote.
4.85/5 (35 votes)
1 Jul 20038 min read 183.6K   4.9K   122  
A set of source code and project browsers to compliment Visual Studio.
#include "stdafx.h"
#include "Resource.h"

#include "ESBImageList.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

using namespace std;
const COLORREF TRANSPARENCY_COLOR = RGB(255,0,255); //white



ESBImageList::ESBImageList()
{
  Create(16, 16, ILC_COLOR8 | ILC_MASK, 5, 1);
  SetBkColor(CLR_NONE);

  initialize();
}

void ESBImageList::initialize()
{
	struct XX
  { string file; CppTagType type; XX(const string& f, CppTagType t) : file(f), type(t) {}};
  
  const size_t size = 10;
	XX images[size]= {
		XX("res/namespace256.bmp", eNamespace), 
		XX("res/class256.bmp", eClass), XX("res/struct256.bmp", eStruct), XX("res/union256.bmp", eUnion),
		XX("res/enum256.bmp", eEnum), XX("res/typedef256.bmp", eTypedef),
		XX("res/function256.bmp", eFunction), XX("res/method256.bmp", eMethod),  
    XX("res/field256.bmp", eField), XX("res/variable256.bmp", eVariable)
											};

  IconMap icons;
	for(int i = 0; i < size; i++) {
		Bitmap image(images[i].file);
    icons[images[i].type][0] = Add(&image, TRANSPARENCY_COLOR); 
	}

  super::initialize(icons);
}

ESBImageList& ESBImageList::instance()
{
  static ESBImageList theInstance;  
  return theInstance;
}


int ESBImageList::createIcon(const IconDescriptor &icon)
{
  CDC *winDC = AfxGetApp()->GetMainWnd()->GetDC();
  
  CDC virtualPainter;
  virtualPainter.CreateCompatibleDC(winDC); 
  
  CSize dim = getImageDimension();
  Bitmap result;
  result.CreateBitmap(dim.cx, dim.cy, virtualPainter.GetDeviceCaps(PLANES), virtualPainter.GetDeviceCaps(BITSPIXEL),0);
  CBitmap* oldBmp = virtualPainter.SelectObject(&result);
  
  //draw the main icon/bitmap
  Draw(&virtualPainter, getIcon(icon.type), CPoint(0,0), ILD_NORMAL);
  
  renderAccessDecorator(icon, result.getDimension(), virtualPainter);
  renderMiscDecorators(icon, CPoint(result.getDimension().cx, 0), virtualPainter);
  
  virtualPainter.SelectObject(oldBmp);
  
  winDC->ReleaseOutputDC();
  return Add(&result, RGB(0,0,0));
}

void ESBImageList::renderAccessDecorator(const IconDescriptor &icon, const CSize& size, CDC &painter)
{  
  if(!icon.decorators.hasAccessDecorator) {
    return;
  }

  string prefix;
  switch(icon.decorators.accessDecorator) {
    case ePublic : prefix = "public"; break;
    case eProtected: prefix = "protected"; break;
    case ePrivate: prefix = "private"; break;
  }
  
  string postfix;
  switch(icon.type) {
    case eField : postfix = "_field"; break;
    case eMethod : postfix = "_method";break;
  }
  
  CPoint topRight(size.cx, 0);
  if(icon.type == eMethod || icon.type == eFunction || icon.type == eField) {
    topRight += CPoint(-8, 5);

  } else {
    topRight.y += 9;
  }
    
  renderDecorator("res\\" + prefix + postfix + "256.bmp", topRight, painter);
}

void ESBImageList::renderMiscDecorators(const IconDescriptor &icon, CPoint offset, CDC &painter)
{  
  switch(icon.decorators.implementationDecorator) {
    case eVirtual : offset = renderDecorator("res\\virtual256.bmp", offset, painter); break;
    case eAbstract : offset = renderDecorator("res\\abstract256.bmp", offset, painter); break;
  }
  
  if(icon.decorators.isSelected) {
    CPoint p(5, 4);
    renderDecorator("res\\selection_arrow256.bmp", p, painter);
  }
  
  if(icon.decorators.hasConstDecorator) {
    offset = renderDecorator("res\\const256.bmp", offset, painter);
  }
  
  if(icon.decorators.hasStaticDecorator) {
    offset = renderDecorator("res\\static256.bmp", offset, painter);
  }

  if(icon.decorators.hasQuestion) {
    offset = renderDecorator("res\\questionmark256.bmp", offset, painter);
  }
  
  if(icon.decorators.hasProblem) {
    offset = renderDecorator("res\\problem256.bmp", offset, painter);
  }
}

//CPoint ESBImageList::renderDecorator(const std::string &file, const CPoint &offset, CDC &painter)
//{
//  return renderDecorator(file, offset, painter, TRANSPARENCY_COLOR);
//}

CPoint ESBImageList::renderDecorator(const std::string &file, const CPoint &offset, CDC &painter/*, const COLORREF &transparency*/)
{
  COLORREF transparency = TRANSPARENCY_COLOR;
  
  Bitmap decorator(file);

  CPoint size = decorator.getDimension();
  CPoint topleft = CPoint(offset.x - size.x, offset.y);
  
  CRect dest(topleft, topleft+size);
  
  decorator.render(painter, topleft, transparency);
  
  const size_t space = 2;
  return CPoint(offset.x - size.x - space, offset.y);
}

CSize ESBImageList::getImageDimension()
{
  IMAGEINFO info;
  GetImageInfo(0, &info);
  return CRect(info.rcImage).Size();
}


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 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


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions