Nicer defaults for Window closing, Implement these with Sign tool, issue #51. Also set centre as default
This commit is contained in:
parent
36b2aa0191
commit
2652309a3f
@ -20,6 +20,7 @@ public:
|
|||||||
SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_);
|
SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Point position_);
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
virtual ~SignWindow() {}
|
virtual ~SignWindow() {}
|
||||||
|
virtual void OnTryExit(ui::Window::ExitMethod method);
|
||||||
class OkayAction: public ui::ButtonAction
|
class OkayAction: public ui::ButtonAction
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -75,6 +76,7 @@ SignWindow::SignWindow(SignTool * tool_, Simulation * sim_, int signID_, ui::Poi
|
|||||||
okayButton->Appearance.BorderInactive = (ui::Colour(200, 200, 200));
|
okayButton->Appearance.BorderInactive = (ui::Colour(200, 200, 200));
|
||||||
okayButton->SetActionCallback(new OkayAction(this));
|
okayButton->SetActionCallback(new OkayAction(this));
|
||||||
AddComponent(okayButton);
|
AddComponent(okayButton);
|
||||||
|
SetOkayButton(okayButton);
|
||||||
|
|
||||||
ui::Label * tempLabel = new ui::Label(ui::Point(8, 48), ui::Point(40, 15), "Justify:");
|
ui::Label * tempLabel = new ui::Label(ui::Point(8, 48), ui::Point(40, 15), "Justify:");
|
||||||
okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
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>("\x9D Left", (int)sign::Left));
|
||||||
justification->AddOption(std::pair<std::string, int>("\x9E Centre", (int)sign::Centre));
|
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->AddOption(std::pair<std::string, int>("\x9F Right", (int)sign::Right));
|
||||||
justification->SetOption(0);
|
justification->SetOption(1);
|
||||||
justification->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
justification->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
|
|
||||||
textField = new ui::Textbox(ui::Point(8, 25), ui::Point(Size.X-16, 17), "");
|
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);
|
ui::Engine::Ref().ShowWindow(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SignWindow::OnTryExit(ui::Window::ExitMethod method)
|
||||||
|
{
|
||||||
|
ui::Engine::Ref().CloseWindow();
|
||||||
|
SelfDestruct();
|
||||||
|
}
|
||||||
|
|
||||||
void SignWindow::OnDraw()
|
void SignWindow::OnDraw()
|
||||||
{
|
{
|
||||||
Graphics * g = ui::Engine::Ref().g;
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "Window.h"
|
#include "Window.h"
|
||||||
#include "Component.h"
|
#include "Component.h"
|
||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
|
#include "interface/Button.h"
|
||||||
|
|
||||||
using namespace ui;
|
using namespace ui;
|
||||||
|
|
||||||
@ -11,7 +12,9 @@ Window::Window(Point _position, Point _size):
|
|||||||
focusedComponent_(NULL),
|
focusedComponent_(NULL),
|
||||||
AllowExclusiveDrawing(true),
|
AllowExclusiveDrawing(true),
|
||||||
halt(false),
|
halt(false),
|
||||||
destruct(false)
|
destruct(false),
|
||||||
|
cancelButton(NULL),
|
||||||
|
okayButton(NULL)
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
,debugMode(false)
|
,debugMode(false)
|
||||||
#endif
|
#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)
|
void Window::RemoveComponent(unsigned idx)
|
||||||
{
|
{
|
||||||
halt = true;
|
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);
|
OnKeyPress(key, character, shift, ctrl, alt);
|
||||||
|
|
||||||
|
if(key == KEY_ESCAPE)
|
||||||
|
OnTryExit(Escape);
|
||||||
|
|
||||||
|
if(key == KEY_ENTER || key == KEY_RETURN)
|
||||||
|
OnTryOkay(Enter);
|
||||||
|
|
||||||
if(destruct)
|
if(destruct)
|
||||||
finalise();
|
finalise();
|
||||||
}
|
}
|
||||||
@ -334,6 +356,10 @@ void Window::DoMouseDown(int x_, int y_, unsigned button)
|
|||||||
}
|
}
|
||||||
|
|
||||||
OnMouseDown(x_, y_, 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)
|
if(destruct)
|
||||||
finalise();
|
finalise();
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ enum ChromeStyle
|
|||||||
//class State;
|
//class State;
|
||||||
class Engine;
|
class Engine;
|
||||||
class Component;
|
class Component;
|
||||||
|
class Button;
|
||||||
|
|
||||||
/* class State
|
/* class State
|
||||||
*
|
*
|
||||||
@ -29,6 +30,9 @@ enum ChromeStyle
|
|||||||
Window(Point _position, Point _size);
|
Window(Point _position, Point _size);
|
||||||
virtual ~Window();
|
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
|
bool AllowExclusiveDrawing; //false will not call draw on objects outside of bounds
|
||||||
|
|
||||||
// Add Component to state
|
// Add Component to state
|
||||||
@ -70,7 +74,13 @@ enum ChromeStyle
|
|||||||
|
|
||||||
void* UserData;
|
void* UserData;
|
||||||
|
|
||||||
|
enum OkayMethod { Enter, OkayButton };
|
||||||
|
enum ExitMethod { MouseOutside, Escape, ExitButton };
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
ui::Button * okayButton;
|
||||||
|
ui::Button * cancelButton;
|
||||||
|
|
||||||
virtual void OnInitialized() {}
|
virtual void OnInitialized() {}
|
||||||
virtual void OnExit() {}
|
virtual void OnExit() {}
|
||||||
virtual void OnTick(float dt) {}
|
virtual void OnTick(float dt) {}
|
||||||
@ -78,6 +88,9 @@ enum ChromeStyle
|
|||||||
virtual void OnFocus() {}
|
virtual void OnFocus() {}
|
||||||
virtual void OnBlur() {}
|
virtual void OnBlur() {}
|
||||||
|
|
||||||
|
virtual void OnTryExit(ExitMethod);
|
||||||
|
virtual void OnTryOkay(OkayMethod);
|
||||||
|
|
||||||
virtual void OnMouseMove(int x, int y, int dx, int dy) {}
|
virtual void OnMouseMove(int x, int y, int dx, int dy) {}
|
||||||
virtual void OnMouseDown(int x, int y, unsigned button) {}
|
virtual void OnMouseDown(int x, int y, unsigned button) {}
|
||||||
virtual void OnMouseUp(int x, int y, unsigned button) {}
|
virtual void OnMouseUp(int x, int y, unsigned button) {}
|
||||||
|
Loading…
Reference in New Issue
Block a user