Nicer defaults for Window closing, Implement these with Sign tool, issue #51. Also set centre as default

This commit is contained in:
Simon Robertshaw 2012-08-03 17:09:34 +01:00
parent 36b2aa0191
commit 2652309a3f
3 changed files with 50 additions and 2 deletions

View File

@ -20,6 +20,7 @@ public:
SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_);
virtual void OnDraw();
virtual ~SignWindow() {}
virtual void OnTryExit(ui::Window::ExitMethod method);
class OkayAction: public ui::ButtonAction
{
public:
@ -75,6 +76,7 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
okayButton->Appearance.BorderInactive = (ui::Colour(200, 200, 200));
okayButton->SetActionCallback(new OkayAction(this));
AddComponent(okayButton);
SetOkayButton(okayButton);
ui::Label * tempLabel = new ui::Label(ui::Point(8, 48), ui::Point(40, 15), "Justify:");
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
@ -86,7 +88,7 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
justification->AddOption(std::pair<std::string, int>("\x9D Left", (int)sign::Left));
justification->AddOption(std::pair<std::string, int>("\x9E Centre", (int)sign::Centre));
justification->AddOption(std::pair<std::string, int>("\x9F Right", (int)sign::Right));
justification->SetOption(0);
justification->SetOption(1);
justification->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
textField = new ui::Textbox(ui::Point(8, 25), ui::Point(Size.X-16, 17), "");
@ -110,6 +112,13 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
ui::Engine::Ref().ShowWindow(this);
}
void SignWindow::OnTryExit(ui::Window::ExitMethod method)
{
ui::Engine::Ref().CloseWindow();
SelfDestruct();
}
void SignWindow::OnDraw()
{
Graphics * g = ui::Engine::Ref().g;

View File

@ -2,6 +2,7 @@
#include "Window.h"
#include "Component.h"
#include "interface/Point.h"
#include "interface/Button.h"
using namespace ui;
@ -11,7 +12,9 @@ Window::Window(Point _position, Point _size):
focusedComponent_(NULL),
AllowExclusiveDrawing(true),
halt(false),
destruct(false)
destruct(false),
cancelButton(NULL),
okayButton(NULL)
#ifdef DEBUG
,debugMode(false)
#endif
@ -75,6 +78,18 @@ void Window::RemoveComponent(Component* c)
}
}
void Window::OnTryExit(ExitMethod method)
{
if(cancelButton)
cancelButton->DoAction();
}
void Window::OnTryOkay(OkayMethod method)
{
if(okayButton)
okayButton->DoAction();
}
void Window::RemoveComponent(unsigned idx)
{
halt = true;
@ -273,6 +288,13 @@ void Window::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool a
}
OnKeyPress(key, character, shift, ctrl, alt);
if(key == KEY_ESCAPE)
OnTryExit(Escape);
if(key == KEY_ENTER || key == KEY_RETURN)
OnTryOkay(Enter);
if(destruct)
finalise();
}
@ -334,6 +356,10 @@ void Window::DoMouseDown(int x_, int y_, unsigned button)
}
OnMouseDown(x_, y_, button);
if(x_ < Position.X || y_ < Position.Y || x_ > Position.X+Size.X || y_ > Position.Y+Size.Y)
OnTryExit(MouseOutside);
if(destruct)
finalise();
}

View File

@ -15,6 +15,7 @@ enum ChromeStyle
//class State;
class Engine;
class Component;
class Button;
/* class State
*
@ -29,6 +30,9 @@ enum ChromeStyle
Window(Point _position, Point _size);
virtual ~Window();
void SetOkayButton(ui::Button * button) { okayButton = button; }
void SetCancelButton(ui::Button * button) { cancelButton = button; }
bool AllowExclusiveDrawing; //false will not call draw on objects outside of bounds
// Add Component to state
@ -70,7 +74,13 @@ enum ChromeStyle
void* UserData;
enum OkayMethod { Enter, OkayButton };
enum ExitMethod { MouseOutside, Escape, ExitButton };
protected:
ui::Button * okayButton;
ui::Button * cancelButton;
virtual void OnInitialized() {}
virtual void OnExit() {}
virtual void OnTick(float dt) {}
@ -78,6 +88,9 @@ enum ChromeStyle
virtual void OnFocus() {}
virtual void OnBlur() {}
virtual void OnTryExit(ExitMethod);
virtual void OnTryOkay(OkayMethod);
virtual void OnMouseMove(int x, int y, int dx, int dy) {}
virtual void OnMouseDown(int x, int y, unsigned button) {}
virtual void OnMouseUp(int x, int y, unsigned button) {}