The first four are the headers, the last is where I'm trying to implement it.
Code:
/**
* \author CSci5107 Guru
*
* \file BrushApp.h
* \brief Main application class for the Brush assignment
*
*/
#ifndef BRUSHAPP_H
#define BRUSHAPP_H
#include "BaseGfxApp.h"
#include "Brush.h"
/** The BrushApp class. This sets up the GUI and the drawing canvas. You shouldn't
need to modify anything here. Instead, fill in your own MyBrushApp class. You
will however need to call setPixel, getPixel, and potentially getData to draw to
the canvas. */
class BrushApp : public BaseGfxApp {
public:
enum UIControlType {
UI_BRUSHTYPE = 0,
UI_COLOR_R = 1,
UI_COLOR_G = 2,
UI_COLOR_B = 3,
UI_FLOW = 4,
UI_RADIUS = 5,
UI_QUIT = 6
};
BrushApp(int argc, char* argv[]);
virtual ~BrushApp();
/// Sets an individual pixel's data on this canvas
void setPixel(int x, int y, const ColorData& color);
/// Gets an individual pixel's data on this canvas
ColorData getPixel(int x, int y) const;
/// Returns a pointer to the array of RGB image data, so you can read/write directly
/// to it, which is faster than using setPixel/getPixel.
unsigned char* getData();
// The following functions are pure virtual, these need to be implemented in a
// MyBrushApp subclass.
virtual void newBrushType(int brushType) = 0;
virtual void newColor(unsigned char red, unsigned char green, unsigned char blue) = 0;
virtual void newRadius(int radius) = 0;
virtual void newFlow(int rate) = 0;
virtual void mousePressed(int x, int y) = 0;
virtual void mouseDragged(int x, int y) = 0;
virtual void mouseReleased(int x, int y) = 0;
void display();
void reshape(int width, int height);
void gluiControl(int controlID);
void mouseMotion(int x, int y);
void leftMouseDown(int x, int y);
void leftMouseUp(int x, int y);
private:
// This is the pointer to the buffer where the actual color data for the canvas
// that we paint on is stored.
unsigned char *m_buffer;
// These are used internally to handle events for the GUI
int m_bt;
int m_r;
int m_f;
int m_cr, m_cg, m_cb;
bool m_drag;
int m_width;
int m_height;
};
#endif
Code:
/**
* \author You!
*
* \file MyBrushApp.h
* \brief Your implementation of the Brush assignment
*
*/
#ifndef MYBRUSHAPP_H
#define MYBRUSHAPP_H
#include "BrushApp.h"
#include "Brush.h"
/** This is your implementation of the Brush application */
class MyBrushApp : public BrushApp {
public:
MyBrushApp(int argc, char* argv[]);
virtual ~MyBrushApp();
/// Need to switch to using brushType (see Brush.h) for enum values
void newBrushType(int brushType);
/// Need to switch the brush color
void newColor(unsigned char red, unsigned char green, unsigned char blue);
/// Need to set a new radius for the brush
void newRadius(int radius);
/// Need to set a new flow rate for the brush
void newFlow(int rate);
/// This is called when the left mouse button is first pressed down
void mousePressed(int x, int y);
/// This is called when the mouse moves and the left button is still held down
void mouseDragged(int x, int y);
/// This is called when the left mouse button is released
void mouseReleased(int x, int y);
private:
/// Pointer to the current brush
Brush *m_brush;
};
#endif
Code:
/**
* \author CSci5107 Guru
*
* \file Brush.h
* \brief Superclass for brushes
*
*/
#ifndef __BRUSH_H__ //header guards
#define __BRUSH_H__
#include "CommonInc.h"
// An enum for brush types
enum BRUSH_TYPE {
BRUSH_CONSTANT,
BRUSH_LINEAR,
BRUSH_QUADRATIC,
BRUSH_GAUSSIAN,
BRUSH_SPECIAL
};
struct ColorData {
unsigned char r, g, b;
};
class BrushApp; // forward declaration
/// This is the superclass for brushes.
class Brush {
public:
/// Constructor for brush. Pass it the initial color, flow and radius.
Brush(ColorData color, int flow, int radius);
/// Destructor for brush. Clean up all brush allocated resources.
virtual ~Brush();
/// Set the brush color.
void setColor(ColorData color);
/// Set the flow of the brush.
void setFlow(int flow);
/// Set the radius of the brush.
void setRadius(int radius);
/// Apply the brush one time centered at (x,y) on the drawing "canvas" that is
/// part of brushApp. Hint: Call brushApp->setPixel and getPixel to do the painting.
void paintOnce(int x, int y, BrushApp* brushApp);
protected:
/// Pure virtual function. You have to override this in subclasses
virtual void makeMask() = 0;
// C++ coding convention is to put m_ in front of member variables
/// This is a pointer to the brush mask.
float* m_mask;
/// Color for the current brush.
ColorData m_color;
/// The flow setting of the brush.
int m_flow;
/// The radius setting of the brush.
int m_radius;
};
#endif // __BRUSH_H__
Code:
/**
* \author CSci5107 Guru
*
* \file ConstantBrush.h
* \brief This is a constant brush.
*
*/
#ifndef CONSTANTBRUSH_H
#define CONSTANTBRUSH_H
#include "Brush.h"
/// This is a constant brush with equal mask distribution in a circle.
class ConstantBrush : public Brush {
public:
ConstantBrush(ColorData color, int flow, int radius);
virtual ~ConstantBrush();
protected:
void makeMask();
};
#endif
Code:
#include "MyBrushApp.h"
MyBrushApp::MyBrushApp(int argc, char* argv[]) : BrushApp(argc, argv)
{
}
MyBrushApp::~MyBrushApp()
{
}
//Here's the function I'm getting my error on.
void
MyBrushApp::newBrushType(int brushType)
{
cout << "newBrushType " << brushType << endl;
if (brushType == 0) { //Constant
m_brush = new ConstantBrush(m_brush->m_color, m_brush->m_flow, m_brush->m_radius);
} else if(brushType == 1){ //Linear
m_brush = new LinearBrush(m_brush->m_color, m_brush->m_flow, m_brush->m_radius);
} else if(brushType == 2){ //Quadratic
m_brush = new QuadraticBrush(m_brush->m_color, m_brush->m_flow, m_brush->m_radius);
}
}
void
MyBrushApp::newColor(unsigned char red, unsigned char green, unsigned char blue)
{
cout << "newColor " << (int)red << " " << (int)green << " " << (int)blue << endl;
ColorData brushColor;
brushColor.r = red;
brushColor.g = green;
brushColor.b = blue;
m_brush->setColor(brushColor);
}
void
MyBrushApp::newRadius(int radius)
{
cout << "newRadius " << radius << endl;
m_brush->setRadius(radius);
}
void
MyBrushApp::newFlow(int rate)
{
cout << "newFlow " << rate << endl;
m_brush->setFlow(rate);
}
// Tells us we should place one paint stroke
void
MyBrushApp::mousePressed(int x, int y)
{
cout << "mousePressed " << x << " " << y << endl;
m_brush->paintOnce(x,y,this);
}
// Tells us we should place another single paint stroke
void
MyBrushApp::mouseDragged(int x, int y)
{
cout << "mouseDragged " << x << " " << y << endl;
}
void
MyBrushApp::mouseReleased(int x, int y)
{
cout << "mouseReleased " << x << " " << y << endl;
}
If you need more, let me know.