Custom brushes loaded from "Brushes" folder, format is a simple RAW 8bit greyscale square format
This commit is contained in:
parent
483e907702
commit
045f5e14c2
56
src/game/BitmapBrush.h
Normal file
56
src/game/BitmapBrush.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* BitmapBrush.h
|
||||||
|
*
|
||||||
|
* Created on: Nov 18, 2012
|
||||||
|
* Author: Simon Robertshaw
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BTIMAPBRUSH_H_
|
||||||
|
#define BTIMAPBRUSH_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <cmath>
|
||||||
|
#include "Brush.h"
|
||||||
|
|
||||||
|
class BitmapBrush: public Brush
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BitmapBrush(std::vector<unsigned char> newBitmap, ui::Point rectSize_):
|
||||||
|
Brush(ui::Point(0, 0))
|
||||||
|
{
|
||||||
|
ui::Point newSize = rectSize_;
|
||||||
|
|
||||||
|
//Ensure the rect has odd dimentions so we can pull an integer radius with a 1x1 centre
|
||||||
|
if(!(newSize.X % 2))
|
||||||
|
newSize.X += 1;
|
||||||
|
if(!(newSize.Y % 2))
|
||||||
|
newSize.Y += 1;
|
||||||
|
|
||||||
|
radius = (newSize-ui::Point(1, 1))/2;
|
||||||
|
size = newSize;
|
||||||
|
|
||||||
|
if(bitmap)
|
||||||
|
delete[] bitmap;
|
||||||
|
bitmap = new unsigned char[size.X*size.Y];
|
||||||
|
std::fill(bitmap, bitmap+(size.X*size.Y), 0);
|
||||||
|
for(int y = 0; y < rectSize_.Y; y++)
|
||||||
|
{
|
||||||
|
for(int x = 0; x < rectSize_.X; x++)
|
||||||
|
{
|
||||||
|
bitmap[(y*size.X)+x] = newBitmap[(y*rectSize_.X)+x];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
updateOutline();
|
||||||
|
};
|
||||||
|
virtual void SetRadius(ui::Point radius)
|
||||||
|
{
|
||||||
|
//Do nothing... this brush is a fixed size
|
||||||
|
}
|
||||||
|
virtual void GenerateBitmap()
|
||||||
|
{
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* BTIMAPBRUSH_H_ */
|
@ -61,7 +61,7 @@ public:
|
|||||||
{
|
{
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
void SetRadius(ui::Point radius)
|
virtual void SetRadius(ui::Point radius)
|
||||||
{
|
{
|
||||||
this->radius = radius;
|
this->radius = radius;
|
||||||
this->size = radius+radius+ui::Point(1, 1);
|
this->size = radius+radius+ui::Point(1, 1);
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "Brush.h"
|
#include "Brush.h"
|
||||||
#include "EllipseBrush.h"
|
#include "EllipseBrush.h"
|
||||||
#include "TriangleBrush.h"
|
#include "TriangleBrush.h"
|
||||||
|
#include "BitmapBrush.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
#include "client/GameSave.h"
|
#include "client/GameSave.h"
|
||||||
#include "game/DecorationTool.h"
|
#include "game/DecorationTool.h"
|
||||||
@ -310,6 +311,26 @@ void GameModel::BuildMenus()
|
|||||||
brushList.push_back(new Brush(ui::Point(4, 4)));
|
brushList.push_back(new Brush(ui::Point(4, 4)));
|
||||||
brushList.push_back(new TriangleBrush(ui::Point(4, 4)));
|
brushList.push_back(new TriangleBrush(ui::Point(4, 4)));
|
||||||
|
|
||||||
|
//Load more from brushes folder
|
||||||
|
std::vector<string> brushFiles = Client::Ref().DirectorySearch(BRUSH_DIR, "", ".ptb");
|
||||||
|
for(int i = 0; i < brushFiles.size(); i++)
|
||||||
|
{
|
||||||
|
std::vector<unsigned char> brushData = Client::Ref().ReadFile(brushFiles[i]);
|
||||||
|
if(!brushData.size())
|
||||||
|
{
|
||||||
|
std::cout << "Brushes: Skipping " << brushFiles[i] << ". Could not open" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int dimension = std::sqrt(brushData.size());
|
||||||
|
if(dimension * dimension != brushData.size())
|
||||||
|
{
|
||||||
|
std::cout << "Brushes: Skipping " << brushFiles[i] << ". Invalid bitmap size" << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
brushList.push_back(new BitmapBrush(brushData, ui::Point(dimension, dimension)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Set default tools
|
//Set default tools
|
||||||
regularToolset[0] = GetToolFromIdentifier("DEFAULT_PT_DUST");
|
regularToolset[0] = GetToolFromIdentifier("DEFAULT_PT_DUST");
|
||||||
regularToolset[1] = GetToolFromIdentifier("DEFAULT_PT_NONE");
|
regularToolset[1] = GetToolFromIdentifier("DEFAULT_PT_NONE");
|
||||||
|
Loading…
Reference in New Issue
Block a user