Ups, I get a
Quote: "Error obtaining Source Code, invalid ID. Sorry but I've given up."
. Attaching it didn't work, obviously. Sorry.
Well, here is it with <code> tags:
The header file
// SimpleWindow.h
#pragma once
class CSimpleWindow
{
public:
CSimpleWindow(void);
~CSimpleWindow(void);
void SetColors(int iForegroundColor, int iBackgroundColor, int iLineColor);
void SetSizeAndPosition(int iWidth, int iHeight, int iPositionX, int iPositionY);
void SetTitle(char *pTitle, int iFontSize);
void SetText(char *pText, int iFontSize);
void Draw(void);
private:
int m_iBGColor; // Background Color
int m_iFGColor; // ForegroundColor
int m_iLineColor; // Color of bounding lines
int m_iWidth;
int m_iHeight;
int m_iXCenter;
int m_iX1;
int m_iY1;
int m_iX2;
int m_iY2;
int m_iTitleFontSize;
int m_iTextFontSize;
char *m_pTitle;
char *m_pText;
};
The cpp file
// SimpleWindow.cpp
#include "stdafx.h"
CSimpleWindow::CSimpleWindow(void)
{
m_iFGColor = dbRgb(250,250,250); // Light grey
m_iBGColor = dbRgb(100,100,100); // Dark grey
m_iLineColor = dbRgb(255, 50, 50); // Some red'ish
m_pTitle = NULL;
m_pText = NULL;
// Initially, draw it centered
SetSizeAndPosition(300, 400, dbScreenWidth()/2-150, dbScreenHeight()/2-200);
SetTitle(NULL, 0);
SetText(NULL, 0);
}
CSimpleWindow::~CSimpleWindow(void)
{
if (m_pTitle) delete(m_pTitle);
if (m_pText) delete(m_pText);
}
void CSimpleWindow::SetColors(int iForegroundColor, int iBackgroundColor, int iLineColor)
{
m_iFGColor = iForegroundColor;
m_iBGColor = iBackgroundColor;
m_iLineColor = iLineColor;
}
void CSimpleWindow::SetSizeAndPosition(int iWidth, int iHeight, int iPositionX, int iPositionY)
{
m_iWidth = iWidth;
m_iHeight = iHeight;
m_iX1 = iPositionX;
m_iY1 = iPositionY;
m_iX2 = m_iX1+iWidth;
m_iY2 = m_iY1+iHeight;
}
void CSimpleWindow::SetTitle(char *pTitle, int iFontSize)
{
if (m_pTitle)
{
delete(m_pTitle);
m_pTitle = NULL;
}
// If NULL was given, return. Title will not be drawn afterwards
if (!pTitle) return;
m_iTitleFontSize = iFontSize;
int i = (int) strlen(pTitle) + 1;
m_pTitle = new char[i];
strncpy(m_pTitle,pTitle,i);
}
void CSimpleWindow::SetText(char *pText, int iFontSize)
{
if (m_pText)
{
delete(m_pText);
m_pText = NULL;
}
// If NULL was given, return. Text will not be drawn afterwards
if (!pText) return;
m_iTextFontSize = iFontSize;
int i = (int) strlen(pText) + 1;
m_pText = new char[i];
strncpy(m_pText,pText,i);
}
void CSimpleWindow::Draw(void)
{
dbSetTextToNormal();
dbSetTextToTransparent();
dbSetTextFont("Arial");
// Draw the frame (a box, too)
dbInk(m_iLineColor, 0);
dbBox(m_iX1, m_iY1, m_iX2, m_iY2);
// Draw the window background
dbInk(m_iBGColor, 0);
dbBox(m_iX1+2, m_iY1+2, m_iX2-2, m_iY2-2);
int iTitleOffset = 0;
// Draw a title, if any
if (m_pTitle)
{
iTitleOffset = m_iTitleFontSize;
dbSetTextSize(m_iTitleFontSize);
dbInk(m_iFGColor, 0);
dbCenterText((int)((m_iX1+m_iX2)/2), m_iY1, m_pTitle);
}
// Draw text, if any
if (m_pText)
{
dbSetTextSize(m_iTextFontSize);
dbInk(m_iFGColor, 0);
dbText(m_iX1+5, m_iY1+iTitleOffset, m_pText);
}
}