Started on dropdown control

This commit is contained in:
Simon Robertshaw 2012-04-17 15:56:57 +01:00
parent c3c31b20b0
commit c261030cef
4 changed files with 110 additions and 0 deletions

View File

@ -0,0 +1,75 @@
/*
* DropDown.cpp
*
* Created on: Apr 16, 2012
* Author: Simon
*/
#include "DropDown.h"
namespace ui {
class DropDownWindow: public ui::Window {
Colour background, activeBackground;
Colour border, activeBorder;
Colour text, activeText;
bool isMouseInside;
public:
DropDownWindow(Point position, Point size, Colour background, Colour activeBackground, Colour border, Colour activeBorder, Colour text, Colour activeText):
Window(position, size),
background(background),
activeBackground(activeBackground),
border(border),
activeBorder(activeBorder),
text(text),
activeText(activeText)
{
}
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);
}
virtual ~DropDownWindow() {}
};
DropDown::DropDown(Point position, Point size):
Component(position, size),
isMouseInside(false)
{
activeText = background = Colour(0, 0, 0);
text = activeBackground = border = activeBorder = Colour(255, 255, 255);
}
void DropDown::OnMouseClick(int x, int y, unsigned int button)
{
ui::Engine().Ref().ShowWindow(new DropDownWindow(ui::Point(50, 50), ui::Point(50, 50), background, activeBackground, border, activeBorder, text, activeText));
}
void DropDown::Draw(const Point& screenPos)
{
Graphics * g = ui::Engine::Ref().g;
Point Position = screenPos;
if(isMouseInside)
{
g->fillrect(Position.X-1, Position.Y-1, Size.X+2, Size.Y+2, activeBackground.Red, activeBackground.Green, activeBackground.Blue, 255);
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, activeBorder.Red, activeBorder.Green, activeBorder.Blue, 255);
//g->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, displayText, activeText.Red, activeText.Green, activeText.Blue, 255);
}
else
{
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->drawtext(Position.X+textPosition.X, Position.Y+textPosition.Y+1, displayText, text.Red, text.Green, text.Blue, 255);
}
}
DropDown::~DropDown() {
// TODO Auto-generated destructor stub
}
} /* namespace ui */

29
src/interface/DropDown.h Normal file
View File

@ -0,0 +1,29 @@
/*
* DropDown.h
*
* Created on: Apr 16, 2012
* Author: Simon
*/
#ifndef DROPDOWN_H_
#define DROPDOWN_H_
#include "Component.h"
#include "Colour.h"
namespace ui {
class DropDown: public ui::Component {
Colour background, activeBackground;
Colour border, activeBorder;
Colour text, activeText;
bool isMouseInside;
public:
DropDown(Point position, Point size);
virtual void Draw(const Point& screenPos);
virtual void OnMouseClick(int x, int y, unsigned int button);
virtual ~DropDown();
};
} /* namespace ui */
#endif /* DROPDOWN_H_ */

View File

@ -77,6 +77,9 @@ OptionsView::OptionsView():
tempLabel->SetAlignment(AlignLeft, AlignMiddle); tempLabel->SetAlignment(AlignLeft, AlignMiddle);
AddComponent(tempLabel); AddComponent(tempLabel);
airMode = new ui::DropDown(ui::Point(Size.X-55, 143), ui::Point(50, 16));//, "Water equalisation \bgIntroduced in version 61");
//airMode->SetActionCallback(new WaterEqualisationAction(this));
AddComponent(airMode);
tempLabel = new ui::Label(ui::Point(3, 143), ui::Point(Size.X-24, 16), "Air Simulation Mode"); tempLabel = new ui::Label(ui::Point(3, 143), ui::Point(Size.X-24, 16), "Air Simulation Mode");
tempLabel->SetAlignment(AlignLeft, AlignMiddle); tempLabel->SetAlignment(AlignLeft, AlignMiddle);
AddComponent(tempLabel); AddComponent(tempLabel);

View File

@ -11,6 +11,7 @@
#include "interface/Window.h" #include "interface/Window.h"
#include "OptionsController.h" #include "OptionsController.h"
#include "interface/Checkbox.h" #include "interface/Checkbox.h"
#include "interface/DropDown.h"
#include "OptionsModel.h" #include "OptionsModel.h"
class OptionsModel; class OptionsModel;
@ -21,6 +22,8 @@ class OptionsView: public ui::Window {
ui::Checkbox * ambientHeatSimulation; ui::Checkbox * ambientHeatSimulation;
ui::Checkbox * newtonianGravity; ui::Checkbox * newtonianGravity;
ui::Checkbox * waterEqualisation; ui::Checkbox * waterEqualisation;
ui::DropDown * airMode;
ui::DropDown * gravityMode;
public: public:
OptionsView(); OptionsView();
void NotifySettingsChanged(OptionsModel * sender); void NotifySettingsChanged(OptionsModel * sender);