Render options

This commit is contained in:
Simon Robertshaw 2012-01-27 13:27:40 +00:00
parent 1c971e4b42
commit 2a7628dfd0
11 changed files with 316 additions and 10 deletions

View File

@ -1657,6 +1657,7 @@ Renderer::Renderer(Graphics * g, Simulation * sim):
//Set defauly display modes
SetColourMode(COLOUR_DEFAULT);
AddRenderMode(RENDER_BASC);
AddRenderMode(RENDER_FIRE);
//Prepare the graphics cache

View File

@ -34,7 +34,8 @@ public:
virtual void OnMouseUp(int x, int y, unsigned int button);
void SetActionCallback(CheckboxAction * action);
CheckboxAction * GetActionCallback() { return actionCallback; }
bool IsChecked() { return checked; }
bool GetChecked() { return checked; }
void SetChecked(bool checked_) { checked = checked_; }
virtual ~Checkbox();
};
}

View File

@ -50,6 +50,12 @@ void PreviewView::OnDraw()
g->drawrect(Position.X, Position.Y, XRES/2, YRES/2, 255, 255, 255, 100);
}
void PreviewView::OnMouseDown(int x, int y, unsigned button)
{
if(!(x > Position.X && y > Position.Y && y < Position.Y+Size.Y && x < Position.X+Size.X)) //Clicked outside window
c->Exit();
}
void PreviewView::NotifySaveChanged(PreviewModel * sender)
{
Save * save = sender->GetSave();

View File

@ -27,6 +27,7 @@ public:
void NotifyPreviewChanged(PreviewModel * sender);
void NotifySaveChanged(PreviewModel * sender);
virtual void OnDraw();
virtual void OnMouseDown(int x, int y, unsigned button);
virtual ~PreviewView();
};

View File

@ -30,6 +30,21 @@ void RenderController::UnsetRenderMode(unsigned int renderMode)
renderModel->UnsetRenderMode(renderMode);
}
void RenderController::SetDisplayMode(unsigned int renderMode)
{
renderModel->SetDisplayMode(renderMode);
}
void RenderController::UnsetDisplayMode(unsigned int renderMode)
{
renderModel->UnsetDisplayMode(renderMode);
}
void RenderController::SetColourMode(unsigned int renderMode)
{
renderModel->SetColourMode(renderMode);
}
void RenderController::Exit()
{
if(ui::Engine::Ref().GetWindow() == renderView)

View File

@ -27,6 +27,9 @@ public:
virtual ~RenderController();
void SetRenderMode(unsigned int renderMode);
void UnsetRenderMode(unsigned int renderMode);
void SetDisplayMode(unsigned int renderMode);
void UnsetDisplayMode(unsigned int renderMode);
void SetColourMode(unsigned int renderMode);
};
#endif /* RENDERCONTROLLER_H_ */

View File

@ -16,22 +16,77 @@ void RenderModel::AddObserver(RenderView * observer)
{
observers.push_back(observer);
observer->NotifyRendererChanged(this);
observer->NotifyRenderChanged(this);
observer->NotifyDisplayChanged(this);
observer->NotifyColourChanged(this);
}
void RenderModel::SetRenderMode(unsigned int renderMode)
{
if(renderer)
renderer->AddRenderMode(renderMode);
notifyRenderChanged();
}
void RenderModel::UnsetRenderMode(unsigned int renderMode)
{
if(renderer)
renderer->RemoveRenderMode(renderMode);
notifyRenderChanged();
}
unsigned int RenderModel::GetRenderMode()
{
if(renderer)
return renderer->render_mode;
else
return 0;
}
void RenderModel::SetDisplayMode(unsigned int displayMode)
{
if(renderer)
renderer->AddDisplayMode(displayMode);
notifyDisplayChanged();
}
void RenderModel::UnsetDisplayMode(unsigned int displayMode)
{
if(renderer)
renderer->RemoveDisplayMode(displayMode);
notifyDisplayChanged();
}
unsigned int RenderModel::GetDisplayMode()
{
if(renderer)
return renderer->display_mode;
else
return 0;
}
void RenderModel::SetColourMode(unsigned int colourMode)
{
if(renderer)
renderer->SetColourMode(colourMode);
notifyColourChanged();
}
unsigned int RenderModel::GetColourMode()
{
if(renderer)
return renderer->colour_mode;
else
return 0;
}
void RenderModel::SetRenderer(Renderer * ren)
{
renderer = ren;
notifyRendererChanged();
notifyRenderChanged();
notifyDisplayChanged();
notifyColourChanged();
}
Renderer * RenderModel::GetRenderer()
@ -47,6 +102,30 @@ void RenderModel::notifyRendererChanged()
}
}
void RenderModel::notifyRenderChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifyRenderChanged(this);
}
}
void RenderModel::notifyDisplayChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifyDisplayChanged(this);
}
}
void RenderModel::notifyColourChanged()
{
for(int i = 0; i < observers.size(); i++)
{
observers[i]->NotifyColourChanged(this);
}
}
RenderModel::~RenderModel() {
// TODO Auto-generated destructor stub
}

View File

@ -19,6 +19,9 @@ class RenderModel {
vector<RenderView*> observers;
Renderer * renderer;
void notifyRendererChanged();
void notifyRenderChanged();
void notifyDisplayChanged();
void notifyColourChanged();
public:
RenderModel();
Renderer * GetRenderer();
@ -26,6 +29,12 @@ public:
void SetRenderer(Renderer * ren);
void SetRenderMode(unsigned int renderMode);
void UnsetRenderMode(unsigned int renderMode);
unsigned int GetRenderMode();
void SetDisplayMode(unsigned int displayMode);
void UnsetDisplayMode(unsigned int displayMode);
unsigned int GetDisplayMode();
void SetColourMode(unsigned int colourMode);
unsigned int GetColourMode();
virtual ~RenderModel();
};

View File

@ -13,8 +13,8 @@
class RenderView::RenderModeAction: public ui::CheckboxAction
{
RenderView * v;
unsigned int renderMode;
public:
unsigned int renderMode;
RenderModeAction(RenderView * v_, unsigned int renderMode_)
{
v = v_;
@ -22,23 +22,145 @@ public:
}
virtual void ActionCallback(ui::Checkbox * sender)
{
if(sender->IsChecked())
if(sender->GetChecked())
v->c->SetRenderMode(renderMode);
else
v->c->UnsetRenderMode(renderMode);
}
};
class RenderView::DisplayModeAction: public ui::CheckboxAction
{
RenderView * v;
public:
unsigned int displayMode;
DisplayModeAction(RenderView * v_, unsigned int displayMode_)
{
v = v_;
displayMode = displayMode_;
}
virtual void ActionCallback(ui::Checkbox * sender)
{
if(sender->GetChecked())
v->c->SetDisplayMode(displayMode);
else
v->c->UnsetDisplayMode(displayMode);
}
};
class RenderView::ColourModeAction: public ui::CheckboxAction
{
RenderView * v;
public:
unsigned int colourMode;
ColourModeAction(RenderView * v_, unsigned int colourMode_)
{
v = v_;
colourMode = colourMode_;
}
virtual void ActionCallback(ui::Checkbox * sender)
{
//if(sender->GetChecked())
v->c->SetColourMode(colourMode);
}
};
RenderView::RenderView():
ui::Window(ui::Point(0, 0), ui::Point(XRES, YRES+MENUSIZE)),
ren(NULL)
{
ui::Checkbox * tCheckbox;
tCheckbox = new ui::Checkbox(ui::Point(0, YRES+5), ui::Point(100, 16), "Blob");
tCheckbox = new ui::Checkbox(ui::Point(1, YRES+4), ui::Point(55, 16), "Effects");
renderModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_EFFE));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(1, YRES+4+18), ui::Point(55, 16), "Fire");
renderModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_FIRE));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(61, YRES+4), ui::Point(55, 16), "Glow");
renderModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_GLOW));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(61, YRES+4+18), ui::Point(55, 16), "Blur");
renderModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_BLUR));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(121, YRES+4), ui::Point(55, 16), "Blob");
renderModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_BLOB));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(121, YRES+4+18), ui::Point(55, 16), "Point");
renderModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new RenderModeAction(this, RENDER_BASC));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(186, YRES+4), ui::Point(70, 16), "Alt. Air");
displayModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIRC));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(186, YRES+4+18), ui::Point(70, 16), "Pressure");
displayModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIRP));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(261, YRES+4), ui::Point(70, 16), "Velocity");
displayModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIRV));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(261, YRES+4+18), ui::Point(70, 16), "Air-heat");
displayModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIRH));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(336, YRES+4), ui::Point(70, 16), "Air");
displayModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_AIR));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(336, YRES+4+18), ui::Point(70, 16), "Warp");
displayModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_WARP));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(411, YRES+4), ui::Point(70, 16), "Persistent");
displayModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_PERS));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(411, YRES+4+18), ui::Point(70, 16), "Effect");
displayModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new DisplayModeAction(this, DISPLAY_EFFE));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(486, YRES+4), ui::Point(50, 16), "Heat");
colourModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new ColourModeAction(this, COLOUR_HEAT));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(486, YRES+4+18), ui::Point(50, 16), "Life");
colourModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new ColourModeAction(this, COLOUR_LIFE));
AddComponent(tCheckbox);
tCheckbox = new ui::Checkbox(ui::Point(536, YRES+4+18), ui::Point(50, 16), "H-Gradient");
colourModes.push_back(tCheckbox);
tCheckbox->SetActionCallback(new ColourModeAction(this, COLOUR_GRAD));
AddComponent(tCheckbox);
}
void RenderView::OnMouseDown(int x, int y, unsigned button)
{
if(x > XRES || y < YRES)
c->Exit();
}
void RenderView::NotifyRendererChanged(RenderModel * sender)
@ -46,10 +168,71 @@ void RenderView::NotifyRendererChanged(RenderModel * sender)
ren = sender->GetRenderer();
}
void RenderView::NotifyRenderChanged(RenderModel * sender)
{
for(int i = 0; i < renderModes.size(); i++)
{
if(renderModes[i]->GetActionCallback())
{
//Compares bitmasks at the moment, this means that "Point" is always on when other options that depend on it are, this might confuse some users, TODO: get the full list and compare that?
RenderModeAction * action = (RenderModeAction *)(renderModes[i]->GetActionCallback());
if(action->renderMode == (sender->GetRenderMode() & action->renderMode))
{
renderModes[i]->SetChecked(true);
}
else
{
renderModes[i]->SetChecked(false);
}
}
}
}
void RenderView::NotifyDisplayChanged(RenderModel * sender)
{
for(int i = 0; i < displayModes.size(); i++)
{
if(displayModes[i]->GetActionCallback())
{
DisplayModeAction * action = (DisplayModeAction *)(displayModes[i]->GetActionCallback());
if(action->displayMode == (sender->GetDisplayMode() & action->displayMode))
{
displayModes[i]->SetChecked(true);
}
else
{
displayModes[i]->SetChecked(false);
}
}
}
}
void RenderView::NotifyColourChanged(RenderModel * sender)
{
for(int i = 0; i < colourModes.size(); i++)
{
if(colourModes[i]->GetActionCallback())
{
ColourModeAction * action = (ColourModeAction *)(colourModes[i]->GetActionCallback());
if(action->colourMode == sender->GetColourMode())
{
colourModes[i]->SetChecked(true);
}
else
{
colourModes[i]->SetChecked(false);
}
}
}
}
void RenderView::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;
g->clearrect(0, 0, XRES, YRES+MENUSIZE);
g->draw_line(0, YRES, XRES-1, YRES, 255, 255, 255, XRES+BARSIZE);
g->draw_line(180, YRES, 180, YRES+MENUSIZE, 200, 200, 200, XRES+BARSIZE);
g->draw_line(480, YRES, 480, YRES+MENUSIZE, 200, 200, 200, XRES+BARSIZE);
g->draw_line(XRES-1, 0, XRES-1, YRES+MENUSIZE, 255, 255, 255, XRES+BARSIZE);
if(ren)
{

View File

@ -22,11 +22,19 @@ class RenderView: public ui::Window {
RenderController * c;
Renderer * ren;
std::vector<ui::Checkbox*> renderModes;
std::vector<ui::Checkbox*> displayModes;
std::vector<ui::Checkbox*> colourModes;
public:
class RenderModeAction;
class DisplayModeAction;
class ColourModeAction;
RenderView();
void NotifyRendererChanged(RenderModel * sender);
void NotifyRenderChanged(RenderModel * sender);
void NotifyDisplayChanged(RenderModel * sender);
void NotifyColourChanged(RenderModel * sender);
void AttachController(RenderController * c_) { c = c_; }
void OnMouseDown(int x, int y, unsigned button);
virtual void OnDraw();
virtual ~RenderView();
};

View File

@ -27,10 +27,10 @@
#define EFFECT_GRAVOUT 0x02000000
#define RENDER_EFFE OPTIONS | PSPEC_STICKMAN | EFFECT | PMODE_SPARK | PMODE_FLARE | PMODE_LFLARE
#define RENDER_FIRE OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_ADD | PMODE_BLEND | FIREMODE
#define RENDER_GLOW OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_GLOW | PMODE_ADD | PMODE_BLEND
#define RENDER_BLUR OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_BLUR | PMODE_ADD | PMODE_BLEND
#define RENDER_BLOB OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_BLOB | PMODE_ADD | PMODE_BLEND
#define RENDER_FIRE OPTIONS | PSPEC_STICKMAN | /*PMODE_FLAT |*/ PMODE_ADD | PMODE_BLEND | FIREMODE
#define RENDER_GLOW OPTIONS | PSPEC_STICKMAN | /*PMODE_FLAT |*/ PMODE_GLOW | PMODE_ADD | PMODE_BLEND
#define RENDER_BLUR OPTIONS | PSPEC_STICKMAN | /*PMODE_FLAT |*/ PMODE_BLUR | PMODE_ADD | PMODE_BLEND
#define RENDER_BLOB OPTIONS | PSPEC_STICKMAN | /*PMODE_FLAT |*/ PMODE_BLOB | PMODE_ADD | PMODE_BLEND
#define RENDER_BASC OPTIONS | PSPEC_STICKMAN | PMODE_FLAT | PMODE_ADD | PMODE_BLEND
#define RENDER_NONE OPTIONS | PSPEC_STICKMAN | PMODE_FLAT