From 2a7628dfd0037fde1f504b276b262ebc9328df60 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 27 Jan 2012 13:27:40 +0000 Subject: [PATCH] Render options --- src/Renderer.cpp | 1 + src/interface/Checkbox.h | 3 +- src/preview/PreviewView.cpp | 6 + src/preview/PreviewView.h | 1 + src/render/RenderController.cpp | 15 +++ src/render/RenderController.h | 3 + src/render/RenderModel.cpp | 83 +++++++++++++- src/render/RenderModel.h | 9 ++ src/render/RenderView.cpp | 189 ++++++++++++++++++++++++++++++- src/render/RenderView.h | 8 ++ src/simulation/ElementGraphics.h | 8 +- 11 files changed, 316 insertions(+), 10 deletions(-) diff --git a/src/Renderer.cpp b/src/Renderer.cpp index f6c1fedc2..9d263789c 100644 --- a/src/Renderer.cpp +++ b/src/Renderer.cpp @@ -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 diff --git a/src/interface/Checkbox.h b/src/interface/Checkbox.h index 8abbe1cb4..ba96cc783 100644 --- a/src/interface/Checkbox.h +++ b/src/interface/Checkbox.h @@ -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(); }; } diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index d0bd6dabb..983e730b6 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -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(); diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index 616bffc9e..ac17df588 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -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(); }; diff --git a/src/render/RenderController.cpp b/src/render/RenderController.cpp index 847724594..e92f03905 100644 --- a/src/render/RenderController.cpp +++ b/src/render/RenderController.cpp @@ -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) diff --git a/src/render/RenderController.h b/src/render/RenderController.h index 95a1bcc4c..81e29c2e8 100644 --- a/src/render/RenderController.h +++ b/src/render/RenderController.h @@ -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_ */ diff --git a/src/render/RenderModel.cpp b/src/render/RenderModel.cpp index ef0f65686..65f4a89c9 100644 --- a/src/render/RenderModel.cpp +++ b/src/render/RenderModel.cpp @@ -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) { - renderer->AddRenderMode(renderMode); + if(renderer) + renderer->AddRenderMode(renderMode); + notifyRenderChanged(); } void RenderModel::UnsetRenderMode(unsigned int renderMode) { - renderer->RemoveRenderMode(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 } diff --git a/src/render/RenderModel.h b/src/render/RenderModel.h index 048cfc544..6bdf36e3a 100644 --- a/src/render/RenderModel.h +++ b/src/render/RenderModel.h @@ -19,6 +19,9 @@ class RenderModel { vector 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(); }; diff --git a/src/render/RenderView.cpp b/src/render/RenderView.cpp index 5551615cc..25978bc83 100644 --- a/src/render/RenderView.cpp +++ b/src/render/RenderView.cpp @@ -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) { diff --git a/src/render/RenderView.h b/src/render/RenderView.h index cdf048861..487a53ef0 100644 --- a/src/render/RenderView.h +++ b/src/render/RenderView.h @@ -22,11 +22,19 @@ class RenderView: public ui::Window { RenderController * c; Renderer * ren; std::vector renderModes; + std::vector displayModes; + std::vector 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(); }; diff --git a/src/simulation/ElementGraphics.h b/src/simulation/ElementGraphics.h index a880e713b..2f0946bb9 100644 --- a/src/simulation/ElementGraphics.h +++ b/src/simulation/ElementGraphics.h @@ -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