Ellipse cursor
This commit is contained in:
parent
824d3c069b
commit
e84f0fc6e5
@ -12,6 +12,7 @@
|
||||
|
||||
class Brush
|
||||
{
|
||||
protected:
|
||||
bool * bitmap;
|
||||
ui::Point size;
|
||||
public:
|
||||
|
60
src/game/EllipseBrush.h
Normal file
60
src/game/EllipseBrush.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* ElipseBrush.h
|
||||
*
|
||||
* Created on: Jan 26, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef ELIPSEBRUSH_H_
|
||||
#define ELIPSEBRUSH_H_
|
||||
|
||||
#include "Brush.h"
|
||||
|
||||
class EllipseBrush: public Brush
|
||||
{
|
||||
public:
|
||||
EllipseBrush(ui::Point size_):
|
||||
Brush(size_)
|
||||
{
|
||||
|
||||
};
|
||||
//Draw the brush outline onto the screen
|
||||
virtual void Render(Graphics * g, ui::Point position)
|
||||
{
|
||||
if(!bitmap)
|
||||
GenerateBitmap();
|
||||
//g->fillrect(position.X-size.X-1, position.Y-size.Y-1, (size.X*2)+2, (size.Y*2)+2, 255, 0, 255, 70);
|
||||
for(int x = 0; x <= size.X*2; x++)
|
||||
{
|
||||
for(int y = 0; y <= size.Y*2; y++)
|
||||
{
|
||||
if(bitmap[y*(size.X*2)+x])
|
||||
g->blendpixel(position.X-size.X+x, position.Y-size.Y+y, 255, 0, 255, 70);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void GenerateBitmap()
|
||||
{
|
||||
if(bitmap)
|
||||
free(bitmap);
|
||||
bitmap = (bool *)malloc(sizeof(bool)*(((size.X*2)+1)*((size.Y*2)+1)));
|
||||
int rx = size.X;
|
||||
int ry = size.Y;
|
||||
for(int x = 0; x <= size.X*2; x++)
|
||||
{
|
||||
for(int y = 0; y <= size.Y*2; y++)
|
||||
{
|
||||
if((pow(x-size.X,2)*pow(ry,2)+pow(y-size.Y,2)*pow(rx,2)<=pow(rx,2)*pow(ry,2)))
|
||||
{
|
||||
bitmap[y*(size.X*2)+x] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bitmap[y*(size.X*2)+x] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* ELIPSEBRUSH_H_ */
|
@ -226,6 +226,10 @@ void GameController::Vote(int direction)
|
||||
//TODO: Implement
|
||||
}
|
||||
|
||||
void GameController::ChangeBrush()
|
||||
{
|
||||
gameModel->SetBrush(gameModel->GetBrushID()+1);
|
||||
}
|
||||
|
||||
void GameController::ClearSim()
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ public:
|
||||
void ClearSim();
|
||||
void ReloadSim();
|
||||
void Vote(int direction);
|
||||
void ChangeBrush();
|
||||
};
|
||||
|
||||
#endif // GAMECONTROLLER_H
|
||||
|
@ -5,13 +5,14 @@
|
||||
#include "Renderer.h"
|
||||
#include "interface/Point.h"
|
||||
#include "Brush.h"
|
||||
#include "EllipseBrush.h"
|
||||
|
||||
GameModel::GameModel():
|
||||
activeTool(NULL),
|
||||
sim(NULL),
|
||||
ren(NULL),
|
||||
currentSave(NULL),
|
||||
currentBrush(new Brush(ui::Point(4, 4))),
|
||||
currentBrush(0),
|
||||
currentUser(0, "")
|
||||
{
|
||||
sim = new Simulation();
|
||||
@ -39,6 +40,9 @@ GameModel::GameModel():
|
||||
//sim->wtypes[i]
|
||||
}
|
||||
|
||||
brushList.push_back(new Brush(ui::Point(4, 4)));
|
||||
brushList.push_back(new EllipseBrush(ui::Point(4, 4)));
|
||||
|
||||
activeTool = new ElementTool(1, "TURD", 0, 0, 0);
|
||||
}
|
||||
|
||||
@ -52,6 +56,10 @@ GameModel::~GameModel()
|
||||
}
|
||||
delete menuList[i];
|
||||
}
|
||||
for(int i = 0; i < brushList.size(); i++)
|
||||
{
|
||||
delete brushList[i];
|
||||
}
|
||||
delete sim;
|
||||
delete ren;
|
||||
if(activeTool)
|
||||
@ -59,10 +67,21 @@ GameModel::~GameModel()
|
||||
}
|
||||
|
||||
Brush * GameModel::GetBrush()
|
||||
{
|
||||
return brushList[currentBrush];
|
||||
}
|
||||
|
||||
int GameModel::GetBrushID()
|
||||
{
|
||||
return currentBrush;
|
||||
}
|
||||
|
||||
void GameModel::SetBrush(int i)
|
||||
{
|
||||
currentBrush = i%brushList.size();
|
||||
notifyBrushChanged();
|
||||
}
|
||||
|
||||
void GameModel::AddObserver(GameView * observer){
|
||||
observers.push_back(observer);
|
||||
|
||||
|
@ -25,7 +25,8 @@ private:
|
||||
vector<Tool*> toolList;
|
||||
vector<Menu*> menuList;
|
||||
Menu * activeMenu;
|
||||
Brush * currentBrush;
|
||||
int currentBrush;
|
||||
vector<Brush *> brushList;
|
||||
Save * currentSave;
|
||||
Simulation * sim;
|
||||
Renderer * ren;
|
||||
@ -43,6 +44,7 @@ private:
|
||||
public:
|
||||
GameModel();
|
||||
~GameModel();
|
||||
|
||||
Save * GetSave();
|
||||
Brush * GetBrush();
|
||||
void SetSave(Save * newSave);
|
||||
@ -58,6 +60,8 @@ public:
|
||||
Menu * GetActiveMenu();
|
||||
User GetUser();
|
||||
void SetUser(User user);
|
||||
void SetBrush(int i);
|
||||
int GetBrushID();
|
||||
Simulation * GetSimulation();
|
||||
Renderer * GetRenderer();
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "interface/Window.h"
|
||||
#include "interface/Button.h"
|
||||
#include "interface/Colour.h"
|
||||
#include "interface/Keys.h"
|
||||
|
||||
GameView::GameView():
|
||||
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
|
||||
@ -399,9 +400,12 @@ void GameView::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case ' ':
|
||||
case ' ': //Space
|
||||
c->SetPaused();
|
||||
break;
|
||||
case KEY_TAB: //Tab
|
||||
c->ChangeBrush();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,3 +6,4 @@
|
||||
#define KEY_END SDLK_END
|
||||
#define KEY_BACKSPACE SDLK_BACKSPACE
|
||||
#define KEY_DELETE SDLK_DELETE
|
||||
#define KEY_TAB SDLK_TAB
|
||||
|
Reference in New Issue
Block a user