From f39d2361e7e7ae13f84ab61920930847742b413a Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 14 May 2012 20:47:14 +0100 Subject: [PATCH] Improve appearance of some dialogues, style defaults --- Style.cpp | 9 +++++ Style.h | 14 +++++++ src/Style.cpp | 22 +++++++++++ src/Style.h | 32 +++++++++++++++ src/game/PropertyTool.cpp | 78 +++++++++++++++++++++++++++++++++++++ src/game/Tool.h | 1 + src/interface/Button.cpp | 2 +- src/interface/DropDown.cpp | 25 +++++++----- src/options/OptionsView.cpp | 23 +++++------ 9 files changed, 185 insertions(+), 21 deletions(-) create mode 100644 Style.cpp create mode 100644 Style.h create mode 100644 src/Style.cpp create mode 100644 src/Style.h create mode 100644 src/game/PropertyTool.cpp diff --git a/Style.cpp b/Style.cpp new file mode 100644 index 000000000..f87c83789 --- /dev/null +++ b/Style.cpp @@ -0,0 +1,9 @@ +// +// Style.cpp +// The Powder Toy +// +// Created by Simon Robertshaw on 14/05/2012. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#include diff --git a/Style.h b/Style.h new file mode 100644 index 000000000..827614af8 --- /dev/null +++ b/Style.h @@ -0,0 +1,14 @@ +// +// Style.h +// The Powder Toy +// +// Created by Simon Robertshaw on 14/05/2012. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#ifndef The_Powder_Toy_Style_h +#define The_Powder_Toy_Style_h + + + +#endif diff --git a/src/Style.cpp b/src/Style.cpp new file mode 100644 index 000000000..86388f971 --- /dev/null +++ b/src/Style.cpp @@ -0,0 +1,22 @@ +// +// Style.cpp +// The Powder Toy +// +// Created by Simon Robertshaw on 14/05/2012. +// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// + +#include +#include "Style.h" + +namespace style { + ui::Colour Colour::InformationTitle = ui::Colour(140, 140, 255); + ui::Colour Colour::WarningTitle = ui::Colour(255, 255, 50); + ui::Colour Colour::ErrorTitle = ui::Colour(255, 20, 20); + + ui::Colour Colour::ActiveBorder = ui::Colour(255, 255, 255); + ui::Colour Colour::InactiveBorder = ui::Colour(180, 180, 180); + + ui::Colour Colour::ActiveBackground = ui::Colour(50, 50, 50); + ui::Colour Colour::InactiveBackground = ui::Colour(0, 0, 0); +} \ No newline at end of file diff --git a/src/Style.h b/src/Style.h new file mode 100644 index 000000000..81d3a9eb7 --- /dev/null +++ b/src/Style.h @@ -0,0 +1,32 @@ +// +// Style.h +// The Powder Toy +// +// Created by Simon Robertshaw on 14/05/2012. +// + +#ifndef The_Powder_Toy_Style_h +#define The_Powder_Toy_Style_h +#include "interface/Colour.h" + +namespace style +{ + class Colour + { + public: + static ui::Colour InformationTitle; + static ui::Colour WarningTitle; + static ui::Colour ErrorTitle; + + static ui::Colour ActiveBorder; + static ui::Colour InactiveBorder; + + static ui::Colour ActiveBackground; + static ui::Colour InactiveBackground; + }; + class Metrics + { + }; +} + +#endif diff --git a/src/game/PropertyTool.cpp b/src/game/PropertyTool.cpp new file mode 100644 index 000000000..6d6bb6806 --- /dev/null +++ b/src/game/PropertyTool.cpp @@ -0,0 +1,78 @@ +#include +#include "Style.h" +#include "simulation/Simulation.h" +#include "Tool.h" +#include "interface/Window.h" +#include "interface/Button.h" +#include "interface/Label.h" +#include "interface/Textbox.h" +#include "interface/DropDown.h" + +class PropertyWindow: public ui::Window +{ +public: + ui::DropDown * property; + ui::Textbox * textField; + SignTool * tool; + Simulation * sim; + int signID; + ui::Point position; + PropertyWindow(PropertyTool * tool_, Simulation * sim_, ui::Point position_); + virtual void OnDraw(); + virtual ~PropertyWindow() {} +}; + +class OkayAction: public ui::ButtonAction +{ +public: + PropertyWindow * prompt; + OkayAction(PropertyWindow * prompt_) { prompt = prompt_; } + void ActionCallback(ui::Button * sender) + { + ui::Engine::Ref().CloseWindow(); + + prompt->SelfDestruct(); + } +}; + +PropertyWindow::PropertyWindow(PropertyTool * tool_, Simulation * sim_, ui::Point position_): +ui::Window(ui::Point(-1, -1), ui::Point(200, 87)), +sim(sim_), +position(position_) +{ + ui::Label * messageLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Edit property"); + messageLabel->SetTextColour(style::Colour::InformationTitle); + messageLabel->SetAlignment(AlignLeft, AlignTop); + AddComponent(messageLabel); + + ui::Button * okayButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 17), "OK"); + okayButton->SetAlignment(AlignLeft, AlignBottom); + okayButton->SetBorderColour(ui::Colour(200, 200, 200)); + okayButton->SetActionCallback(new OkayAction(this)); + AddComponent(okayButton); + + property = new ui::DropDown(ui::Point(8, 25), ui::Point(Size.X-16, 17)); + AddComponent(property); + property->AddOption(std::pair("Left", (int)sign::Left)); + property->AddOption(std::pair("Centre", (int)sign::Centre)); + property->AddOption(std::pair("Right", (int)sign::Right)); + property->SetOption(0); + + textField = new ui::Textbox(ui::Point(8, 46), ui::Point(Size.X-16, 16), ""); + textField->SetAlignment(AlignLeft, AlignBottom); + AddComponent(textField); + + ui::Engine::Ref().ShowWindow(this); +} +void PropertyWindow::OnDraw() +{ + Graphics * g = ui::Engine::Ref().g; + + g->clearrect(Position.X-2, Position.Y-2, Size.X+4, Size.Y+4); + g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255); +} + +void PropertyTool::Click(Simulation * sim, Brush * brush, ui::Point position) +{ + new PropertyWindow(this, sim, position); +} \ No newline at end of file diff --git a/src/game/Tool.h b/src/game/Tool.h index 3a66ae450..81b682368 100644 --- a/src/game/Tool.h +++ b/src/game/Tool.h @@ -65,6 +65,7 @@ public: { } virtual ~PropertyTool() {} + virtual void Click(Simulation * sim, Brush * brush, ui::Point position); virtual void Draw(Simulation * sim, Brush * brush, ui::Point position) {}; virtual void DrawLine(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } virtual void DrawRect(Simulation * sim, Brush * brush, ui::Point position1, ui::Point position2) { } diff --git a/src/interface/Button.cpp b/src/interface/Button.cpp index 3bf302b84..5f3a12ab2 100644 --- a/src/interface/Button.cpp +++ b/src/interface/Button.cpp @@ -6,7 +6,6 @@ */ #include - #include "interface/Button.h" #include "Graphics.h" #include "Engine.h" @@ -30,6 +29,7 @@ Button::Button(Point position, Point size, std::string buttonText): { activeText = background = Colour(0, 0, 0); text = activeBackground = border = activeBorder = Colour(255, 255, 255); + TextPosition(); } diff --git a/src/interface/DropDown.cpp b/src/interface/DropDown.cpp index 8b9c976f8..5ad255aa8 100644 --- a/src/interface/DropDown.cpp +++ b/src/interface/DropDown.cpp @@ -6,6 +6,7 @@ */ #include +#include "Style.h" #include "Button.h" #include "DropDown.h" @@ -35,29 +36,31 @@ public: } }; DropDownWindow(DropDown * dropDown): - Window(ui::Point(dropDown->Position.X+dropDown->GetParentWindow()->Position.X-5, dropDown->Position.Y+dropDown->GetParentWindow()->Position.Y-3), ui::Point(dropDown->Size.X+10, dropDown->options.size()*13)), + Window(ui::Point(dropDown->Position.X+dropDown->GetParentWindow()->Position.X-5, dropDown->Position.Y+dropDown->GetParentWindow()->Position.Y-3), ui::Point(dropDown->Size.X+10, 1+dropDown->options.size()*15)), dropDown(dropDown), - background(background), + background(dropDown->background), activeBackground(dropDown->activeBackground), border(dropDown->border), activeBorder(dropDown->activeBorder), text(dropDown->text), activeText(dropDown->activeText) { - int currentY = 0; + int currentY = 1; for(int i = 0; i < dropDown->options.size(); i++) { - Button * tempButton = new Button(Point(0, currentY), Point(Size.X, 14), dropDown->options[i].first); + Button * tempButton = new Button(Point(1, currentY), Point(Size.X-2, 14), dropDown->options[i].first); + tempButton->SetTextColour(dropDown->text); + tempButton->SetBorderColour(dropDown->background); tempButton->SetActionCallback(new ItemSelectedAction(this, dropDown->options[i].first)); AddComponent(tempButton); - currentY += 13; + currentY += 15; } } virtual void OnDraw() { Graphics * g = ui::Engine::Ref().g; - g->fillrect(Position.X, Position.Y, Size.X, Size.Y, background.Red, background.Green, background.Blue, 255); - g->drawrect(Position.X, Position.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, 255); + g->fillrect(Position.X, Position.Y, Size.X, Size.Y, 100, 100, 100, 255); + g->drawrect(Position.X, Position.Y, Size.X, Size.Y, border.Red, border.Green, border.Blue, border.Alpha); } void setOption(std::string option) { @@ -85,8 +88,12 @@ DropDown::DropDown(Point position, Point size): textHAlign(AlignLeft), callback(NULL) { - background = activeBackground = Colour(0, 0, 0); - activeText = text = activeBackground = border = activeBorder = Colour(255, 255, 255); + activeText = text = Colour(255, 255, 255); + + border = style::Colour::InactiveBorder; + activeBorder = style::Colour::ActiveBorder; + background = style::Colour::InactiveBackground; + activeBackground = style::Colour::ActiveBackground; } void DropDown::OnMouseClick(int x, int y, unsigned int button) diff --git a/src/options/OptionsView.cpp b/src/options/OptionsView.cpp index d1066a84b..f88be2606 100644 --- a/src/options/OptionsView.cpp +++ b/src/options/OptionsView.cpp @@ -6,15 +6,16 @@ */ #include "OptionsView.h" +#include "Style.h" #include "interface/Button.h" #include "interface/Label.h" #include "interface/DropDown.h" OptionsView::OptionsView(): - ui::Window(ui::Point(-1, -1), ui::Point(300, 300)){ + ui::Window(ui::Point(-1, -1), ui::Point(300, 206)){ - ui::Label * tempLabel = new ui::Label(ui::Point(3, 3), ui::Point(Size.X-6, 14), "Simulation Options"); - tempLabel->SetTextColour(ui::Colour(255, 220, 0)); + ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options"); + tempLabel->SetTextColour(style::Colour::InformationTitle); tempLabel->SetAlignment(AlignLeft, AlignMiddle); AddComponent(tempLabel); @@ -26,7 +27,7 @@ OptionsView::OptionsView(): virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetHeatSimulation(sender->GetChecked()); } }; - heatSimulation = new ui::Checkbox(ui::Point(3, 23), ui::Point(Size.X-6, 16), "Heat simulation \bgIntroduced in version 34"); + heatSimulation = new ui::Checkbox(ui::Point(8, 23), ui::Point(Size.X-6, 16), "Heat simulation \bgIntroduced in version 34"); heatSimulation->SetActionCallback(new HeatSimulationAction(this)); AddComponent(heatSimulation); tempLabel = new ui::Label(ui::Point(24, heatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd behaviour with very old saves"); @@ -41,7 +42,7 @@ OptionsView::OptionsView(): virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetAmbientHeatSimulation(sender->GetChecked()); } }; - ambientHeatSimulation = new ui::Checkbox(ui::Point(3, 53), ui::Point(Size.X-6, 16), "Ambient heat simulation \bgIntroduced in version 50"); + ambientHeatSimulation = new ui::Checkbox(ui::Point(8, 53), ui::Point(Size.X-6, 16), "Ambient heat simulation \bgIntroduced in version 50"); ambientHeatSimulation->SetActionCallback(new AmbientHeatSimulationAction(this)); AddComponent(ambientHeatSimulation); tempLabel = new ui::Label(ui::Point(24, ambientHeatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd behaviour with old saves"); @@ -56,7 +57,7 @@ OptionsView::OptionsView(): virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetNewtonianGravity(sender->GetChecked()); } }; - newtonianGravity = new ui::Checkbox(ui::Point(3, 83), ui::Point(Size.X-6, 16), "Newtonian gravity \bgIntroduced in version 48"); + newtonianGravity = new ui::Checkbox(ui::Point(8, 83), ui::Point(Size.X-6, 16), "Newtonian gravity \bgIntroduced in version 48"); newtonianGravity->SetActionCallback(new NewtonianGravityAction(this)); AddComponent(newtonianGravity); tempLabel = new ui::Label(ui::Point(24, newtonianGravity->Position.Y+14), ui::Point(Size.X-28, 16), "\bgMay cause poor performance on older computers"); @@ -71,7 +72,7 @@ OptionsView::OptionsView(): virtual void ActionCallback(ui::Checkbox * sender){ v->c->SetWaterEqualisation(sender->GetChecked()); } }; - waterEqualisation = new ui::Checkbox(ui::Point(3, 113), ui::Point(Size.X-6, 16), "Water equalisation \bgIntroduced in version 61"); + waterEqualisation = new ui::Checkbox(ui::Point(8, 113), ui::Point(Size.X-6, 16), "Water equalisation \bgIntroduced in version 61"); waterEqualisation->SetActionCallback(new WaterEqualisationAction(this)); AddComponent(waterEqualisation); tempLabel = new ui::Label(ui::Point(24, waterEqualisation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgMay cause poor performance with a lot of water"); @@ -85,7 +86,7 @@ OptionsView::OptionsView(): AirModeChanged(OptionsView * v): v(v) { } virtual void OptionChanged(ui::DropDown * sender, std::pair option) { v->c->SetAirMode(option.second); } }; - airMode = new ui::DropDown(ui::Point(Size.X-85, 143), ui::Point(80, 16)); + airMode = new ui::DropDown(ui::Point(Size.X-88, 146), ui::Point(80, 16)); AddComponent(airMode); airMode->AddOption(std::pair("On", 0)); airMode->AddOption(std::pair("Pressure off", 1)); @@ -94,7 +95,7 @@ OptionsView::OptionsView(): airMode->AddOption(std::pair("No Update", 4)); airMode->SetActionCallback(new AirModeChanged(this)); - tempLabel = new ui::Label(ui::Point(3, 143), ui::Point(Size.X-90, 16), "Air Simulation Mode"); + tempLabel = new ui::Label(ui::Point(8, 146), ui::Point(Size.X-96, 16), "Air Simulation Mode"); tempLabel->SetAlignment(AlignLeft, AlignMiddle); AddComponent(tempLabel); @@ -106,14 +107,14 @@ OptionsView::OptionsView(): virtual void OptionChanged(ui::DropDown * sender, std::pair option) { v->c->SetGravityMode(option.second); } }; - gravityMode = new ui::DropDown(ui::Point(Size.X-85, 163), ui::Point(80, 16)); + gravityMode = new ui::DropDown(ui::Point(Size.X-88, 166), ui::Point(80, 16)); AddComponent(gravityMode); gravityMode->AddOption(std::pair("Vertical", 0)); gravityMode->AddOption(std::pair("Off", 1)); gravityMode->AddOption(std::pair("Radial", 2)); gravityMode->SetActionCallback(new GravityModeChanged(this)); - tempLabel = new ui::Label(ui::Point(3, 163), ui::Point(Size.X-90, 16), "Gravity Simulation Mode"); + tempLabel = new ui::Label(ui::Point(8, 166), ui::Point(Size.X-96, 16), "Gravity Simulation Mode"); tempLabel->SetAlignment(AlignLeft, AlignMiddle); AddComponent(tempLabel);