To add a new brush to FlashPhotoApp involves creating a new Tool with a Mask, and integrating it into the FlashPhotoApp.cpp file.
MaskFactory.h and <cmath>
m_mask
to be whichever mask you want from MaskFactory by calling MaskFactory::getMask(mask_enum mask_to_make)
where mask_to_make
is the enum value corresponding to the Mask you would like (PEN, ERASER
etc.). If there is no existing Mask to use for the new Tool, follow the instructions for adding a new Mask below.apply()
function inherited from Tool
. By default it will iterate over the Mask (which is a 2D-array) and change the relevant locations on a PixelBuffer by taking into account its current color and mask shape.
Some Tools work slightly different, for example the StampTool
actually uses a PixelBuffer instead of a mask because it is storing an actual image.include.h
file within libphoto
.MaskFactory
. Before doing so, add a new MASK_NAME
(ie. STAMP
) to the mask_enum
enumerated type in Enums.h.
This will make it so other functions can figure out which Mask is relevant.MaskFactory.cpp
, write a new function called MaskFactory::getNewNameMask()
which returns the relevant 2D-array you would like to use for your Tool’s Mask. Don’t forget to add this function to the header file, MaskFactory.h
,
and to specify that it is static
. Lastly, add a case to the switch statement in MaskFactory::getMask()
to call the new function you just made to return the correct mask.FlashPhotoApp.h
, find the line:const int TOOL_NUM = <some_number>
enum ToolEnum
{
PEN,
ERASER,
SPRAY,
CALLIG,
HIGHLIGHT,
STAMP,
BLUR,
NEWTYPE;
};
fillToolArray()
function, set the value of toolsArray
at your new type in the enum to a new version of your Tool:
void FlashPhotoApp::fillToolArray()
{
toolsArray[PEN] = new PenTool();
toolsArray[ERASER] = new EraserTool();
toolsArray[SPRAY] = new SprayCanTool();
toolsArray[CALLIG] = new CalligraphyPenTool();
toolsArray[HIGHLIGHT] = new HighlighterTool();
toolsArray[STAMP] = new StampTool();
toolsArray[BLUR] = new BlurTool();
toolsArray[NEWTYPE] = new NewTool();
}
BLUI_RadioButton
and pass it (radio, “Tool Name”
) in the initGlui()
function:
GLUI_Panel *toolPanel = new GLUI_Panel(m_glui, "Tool Type");
{
GLUI_RadioGroup *radio = new GLUI_RadioGroup(toolPanel, &m_curTool, UI_TOOLTYPE, s_gluicallback);
// Create interface buttons for different tools:
new GLUI_RadioButton(radio, "Pen");
new GLUI_RadioButton(radio, "Eraser");
new GLUI_RadioButton(radio, "Spray Can");
new GLUI_RadioButton(radio, "Caligraphy Pen");
new GLUI_RadioButton(radio, "Highlighter");
new GLUI_RadioButton(radio, "Stamp");
new GLUI_RadioButton(radio, "Blur");
new GLUI_RadioButton(radio, “Tool Name”);
}
updateToolColors()
to make sure the function does not try to set the color of the Tool. This is done by adding another expression in the check to see if i is the new type in the enum you made, such as:if (i != ERASER && i != BLUR && i != STAMP && i != NEWTYPE)
You’re done!