mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-11 10:54:15 +02:00
Ellipse cursor
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
class Brush
|
class Brush
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
bool * bitmap;
|
bool * bitmap;
|
||||||
ui::Point size;
|
ui::Point size;
|
||||||
public:
|
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
|
//TODO: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameController::ChangeBrush()
|
||||||
|
{
|
||||||
|
gameModel->SetBrush(gameModel->GetBrushID()+1);
|
||||||
|
}
|
||||||
|
|
||||||
void GameController::ClearSim()
|
void GameController::ClearSim()
|
||||||
{
|
{
|
||||||
|
@@ -47,6 +47,7 @@ public:
|
|||||||
void ClearSim();
|
void ClearSim();
|
||||||
void ReloadSim();
|
void ReloadSim();
|
||||||
void Vote(int direction);
|
void Vote(int direction);
|
||||||
|
void ChangeBrush();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GAMECONTROLLER_H
|
#endif // GAMECONTROLLER_H
|
||||||
|
@@ -5,13 +5,14 @@
|
|||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
#include "Brush.h"
|
#include "Brush.h"
|
||||||
|
#include "EllipseBrush.h"
|
||||||
|
|
||||||
GameModel::GameModel():
|
GameModel::GameModel():
|
||||||
activeTool(NULL),
|
activeTool(NULL),
|
||||||
sim(NULL),
|
sim(NULL),
|
||||||
ren(NULL),
|
ren(NULL),
|
||||||
currentSave(NULL),
|
currentSave(NULL),
|
||||||
currentBrush(new Brush(ui::Point(4, 4))),
|
currentBrush(0),
|
||||||
currentUser(0, "")
|
currentUser(0, "")
|
||||||
{
|
{
|
||||||
sim = new Simulation();
|
sim = new Simulation();
|
||||||
@@ -39,6 +40,9 @@ GameModel::GameModel():
|
|||||||
//sim->wtypes[i]
|
//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);
|
activeTool = new ElementTool(1, "TURD", 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,6 +56,10 @@ GameModel::~GameModel()
|
|||||||
}
|
}
|
||||||
delete menuList[i];
|
delete menuList[i];
|
||||||
}
|
}
|
||||||
|
for(int i = 0; i < brushList.size(); i++)
|
||||||
|
{
|
||||||
|
delete brushList[i];
|
||||||
|
}
|
||||||
delete sim;
|
delete sim;
|
||||||
delete ren;
|
delete ren;
|
||||||
if(activeTool)
|
if(activeTool)
|
||||||
@@ -59,10 +67,21 @@ GameModel::~GameModel()
|
|||||||
}
|
}
|
||||||
|
|
||||||
Brush * GameModel::GetBrush()
|
Brush * GameModel::GetBrush()
|
||||||
|
{
|
||||||
|
return brushList[currentBrush];
|
||||||
|
}
|
||||||
|
|
||||||
|
int GameModel::GetBrushID()
|
||||||
{
|
{
|
||||||
return currentBrush;
|
return currentBrush;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameModel::SetBrush(int i)
|
||||||
|
{
|
||||||
|
currentBrush = i%brushList.size();
|
||||||
|
notifyBrushChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void GameModel::AddObserver(GameView * observer){
|
void GameModel::AddObserver(GameView * observer){
|
||||||
observers.push_back(observer);
|
observers.push_back(observer);
|
||||||
|
|
||||||
|
@@ -25,7 +25,8 @@ private:
|
|||||||
vector<Tool*> toolList;
|
vector<Tool*> toolList;
|
||||||
vector<Menu*> menuList;
|
vector<Menu*> menuList;
|
||||||
Menu * activeMenu;
|
Menu * activeMenu;
|
||||||
Brush * currentBrush;
|
int currentBrush;
|
||||||
|
vector<Brush *> brushList;
|
||||||
Save * currentSave;
|
Save * currentSave;
|
||||||
Simulation * sim;
|
Simulation * sim;
|
||||||
Renderer * ren;
|
Renderer * ren;
|
||||||
@@ -43,6 +44,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
GameModel();
|
GameModel();
|
||||||
~GameModel();
|
~GameModel();
|
||||||
|
|
||||||
Save * GetSave();
|
Save * GetSave();
|
||||||
Brush * GetBrush();
|
Brush * GetBrush();
|
||||||
void SetSave(Save * newSave);
|
void SetSave(Save * newSave);
|
||||||
@@ -58,6 +60,8 @@ public:
|
|||||||
Menu * GetActiveMenu();
|
Menu * GetActiveMenu();
|
||||||
User GetUser();
|
User GetUser();
|
||||||
void SetUser(User user);
|
void SetUser(User user);
|
||||||
|
void SetBrush(int i);
|
||||||
|
int GetBrushID();
|
||||||
Simulation * GetSimulation();
|
Simulation * GetSimulation();
|
||||||
Renderer * GetRenderer();
|
Renderer * GetRenderer();
|
||||||
};
|
};
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#include "interface/Window.h"
|
#include "interface/Window.h"
|
||||||
#include "interface/Button.h"
|
#include "interface/Button.h"
|
||||||
#include "interface/Colour.h"
|
#include "interface/Colour.h"
|
||||||
|
#include "interface/Keys.h"
|
||||||
|
|
||||||
GameView::GameView():
|
GameView::GameView():
|
||||||
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
|
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)
|
switch(key)
|
||||||
{
|
{
|
||||||
case ' ':
|
case ' ': //Space
|
||||||
c->SetPaused();
|
c->SetPaused();
|
||||||
break;
|
break;
|
||||||
|
case KEY_TAB: //Tab
|
||||||
|
c->ChangeBrush();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -6,3 +6,4 @@
|
|||||||
#define KEY_END SDLK_END
|
#define KEY_END SDLK_END
|
||||||
#define KEY_BACKSPACE SDLK_BACKSPACE
|
#define KEY_BACKSPACE SDLK_BACKSPACE
|
||||||
#define KEY_DELETE SDLK_DELETE
|
#define KEY_DELETE SDLK_DELETE
|
||||||
|
#define KEY_TAB SDLK_TAB
|
||||||
|
Reference in New Issue
Block a user