Skip to content

Commit

Permalink
"Enabled" setting of button is now the old unused "Locked" setting of…
Browse files Browse the repository at this point in the history
… Components, also fix graphical bug with disabled buttons
  • Loading branch information
jacob1 committed Jul 15, 2015
1 parent 37f8038 commit 15537d4
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/Format.cpp
Expand Up @@ -106,12 +106,12 @@ std::string format::CleanString(std::string dirtyString, bool ascii, bool color,
dirtyString[i] = ' ';
break;
default:
// if less than ascii 20 or greater than ascii 126, delete
if (numeric && (dirtyString[i] < '0' || dirtyString[i] > '9'))
{
dirtyString.erase(i, 1);
i--;
}
// if less than ascii 20 or greater than ascii 126, delete
else if (ascii && (dirtyString[i] < ' ' || dirtyString[i] > '~'))
{
dirtyString.erase(i, 1);
Expand Down
1 change: 0 additions & 1 deletion src/gui/interface/Button.cpp
Expand Up @@ -8,7 +8,6 @@ namespace ui {

Button::Button(Point position, Point size, std::string buttonText, std::string toolTip):
Component(position, size),
Enabled(true),
ButtonText(buttonText),
toolTip(toolTip),
isButtonDown(false),
Expand Down
2 changes: 0 additions & 2 deletions src/gui/interface/Button.h
Expand Up @@ -24,8 +24,6 @@ class Button : public Component
Button(Point position = Point(0, 0), Point size = Point(0, 0), std::string buttonText = "", std::string toolTip = "");
virtual ~Button();

bool Enabled;

virtual void OnMouseClick(int x, int y, unsigned int button);
virtual void OnMouseUnclick(int x, int y, unsigned int button);
//virtual void OnMouseUp(int x, int y, unsigned int button);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/interface/Component.cpp
Expand Up @@ -19,7 +19,7 @@ Component::Component(Window* parent_state):
menu(NULL),
Position(Point(0,0)),
Size(Point(0,0)),
Locked(false),
Enabled(true),
Visible(true)
{

Expand All @@ -35,7 +35,7 @@ Component::Component(Point position, Point size):
menu(NULL),
Position(position),
Size(size),
Locked(false),
Enabled(true),
Visible(true)
{

Expand All @@ -51,7 +51,7 @@ Component::Component():
menu(NULL),
Position(Point(0,0)),
Size(Point(0,0)),
Locked(false),
Enabled(true),
Visible(true)
{

Expand Down
2 changes: 1 addition & 1 deletion src/gui/interface/Component.h
Expand Up @@ -41,7 +41,7 @@ namespace ui

Point Position;
Point Size;
bool Locked;
bool Enabled;
bool Visible;

ui::Appearance Appearance;
Expand Down
20 changes: 10 additions & 10 deletions src/gui/interface/Panel.cpp
Expand Up @@ -193,8 +193,8 @@ void Panel::OnMouseClick(int localx, int localy, unsigned button)
//check if clicked a child
for(int i = children.size()-1; i >= 0 ; --i)
{
//child must be unlocked
if(!children[i]->Locked)
//child must be enabled
if(children[i]->Enabled)
{
//is mouse inside?
if( localx >= children[i]->Position.X + ViewportPosition.X &&
Expand Down Expand Up @@ -223,7 +223,7 @@ void Panel::OnMouseDown(int x, int y, unsigned button)
XOnMouseDown(x, y, button);
for (size_t i = 0; i < children.size(); ++i)
{
if(!children[i]->Locked)
if(children[i]->Enabled)
children[i]->OnMouseDown(x, y, button);
}
}
Expand All @@ -233,7 +233,7 @@ void Panel::OnMouseHover(int localx, int localy)
// check if hovering on children
for (int i = children.size() - 1; i >= 0; --i)
{
if (!children[i]->Locked)
if (children[i]->Enabled)
{
if( localx >= children[i]->Position.X &&
localy >= children[i]->Position.Y &&
Expand All @@ -255,7 +255,7 @@ void Panel::OnMouseMoved(int localx, int localy, int dx, int dy)
XOnMouseMoved(localx, localy, dx, dy);
for (size_t i = 0; i < children.size(); ++i)
{
if(!children[i]->Locked)
if(children[i]->Enabled)
children[i]->OnMouseMoved(localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y, dx, dy);
}
}
Expand All @@ -265,7 +265,7 @@ void Panel::OnMouseMovedInside(int localx, int localy, int dx, int dy)
mouseInside = true;
for (size_t i = 0; i < children.size(); ++i)
{
if (!children[i]->Locked)
if (children[i]->Enabled)
{
Point local (localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y)
, prevlocal (local.X - dx, local.Y - dy);
Expand Down Expand Up @@ -327,7 +327,7 @@ void Panel::OnMouseUnclick(int localx, int localy, unsigned button)
for(int i = children.size()-1; i >= 0 ; --i)
{
//child must be unlocked
if(!children[i]->Locked)
if(children[i]->Enabled)
{
//is mouse inside?
if( localx >= children[i]->Position.X + ViewportPosition.X &&
Expand All @@ -354,7 +354,7 @@ void Panel::OnMouseUp(int x, int y, unsigned button)
XOnMouseUp(x, y, button);
for (size_t i = 0; i < children.size(); ++i)
{
if (!children[i]->Locked)
if (children[i]->Enabled)
children[i]->OnMouseUp(x, y, button);
}
}
Expand All @@ -364,7 +364,7 @@ void Panel::OnMouseWheel(int localx, int localy, int d)
XOnMouseWheel(localx, localy, d);
for (size_t i = 0; i < children.size(); ++i)
{
if (!children[i]->Locked)
if (children[i]->Enabled)
children[i]->OnMouseWheel(localx - children[i]->Position.X - ViewportPosition.X, localy - children[i]->Position.Y - ViewportPosition.Y, d);
}
}
Expand All @@ -376,7 +376,7 @@ void Panel::OnMouseWheelInside(int localx, int localy, int d)
for (int i = children.size()-1; i >= 0 ; --i)
{
//child must be unlocked
if (!children[i]->Locked)
if (children[i]->Enabled)
{
//is mouse inside?
if (localx >= children[i]->Position.X + ViewportPosition.X &&
Expand Down
1 change: 0 additions & 1 deletion src/gui/interface/Textbox.cpp
Expand Up @@ -3,7 +3,6 @@
#include <stdexcept>
#include "Config.h"
#include "Format.h"
//#include "Misc.h"
#include "gui/interface/Point.h"
#include "gui/interface/Textbox.h"
#include "gui/interface/Keys.h"
Expand Down
23 changes: 12 additions & 11 deletions src/gui/interface/Window.cpp
Expand Up @@ -236,7 +236,7 @@ void Window::DoTick(float dt)
//on mouse hover
for (int i = Components.size() - 1; i >= 0 && !halt; --i)
{
if (!Components[i]->Locked &&
if (Components[i]->Enabled &&
ui::Engine::Ref().GetMouseX() >= Components[i]->Position.X+Position.X &&
ui::Engine::Ref().GetMouseY() >= Components[i]->Position.Y+Position.Y &&
ui::Engine::Ref().GetMouseX() < Components[i]->Position.X+Position.X + Components[i]->Size.X &&
Expand Down Expand Up @@ -352,7 +352,7 @@ void Window::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool a
//on key press
if (focusedComponent_ != NULL)
{
if (!focusedComponent_->Locked && focusedComponent_->Visible)
if (focusedComponent_->Enabled && focusedComponent_->Visible)
focusedComponent_->OnKeyPress(key, character, shift, ctrl, alt);
}

Expand All @@ -378,7 +378,7 @@ void Window::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool
//on key unpress
if (focusedComponent_ != NULL)
{
if (!focusedComponent_->Locked && focusedComponent_->Visible)
if (focusedComponent_->Enabled && focusedComponent_->Visible)
focusedComponent_->OnKeyRelease(key, character, shift, ctrl, alt);
}

Expand All @@ -396,7 +396,7 @@ void Window::DoMouseDown(int x_, int y_, unsigned button)
bool clickState = false;
for (int i = Components.size() - 1; i > -1 && !halt; --i)
{
if (!Components[i]->Locked && Components[i]->Visible)
if (Components[i]->Enabled && Components[i]->Visible)
{
if (x >= Components[i]->Position.X && y >= Components[i]->Position.Y && x < Components[i]->Position.X + Components[i]->Size.X && y < Components[i]->Position.Y + Components[i]->Size.Y)
{
Expand All @@ -422,7 +422,7 @@ void Window::DoMouseDown(int x_, int y_, unsigned button)
//on mouse down
for (int i = Components.size() - 1; i > -1 && !halt; --i)
{
if (!Components[i]->Locked && Components[i]->Visible)
if (Components[i]->Enabled && Components[i]->Visible)
Components[i]->OnMouseDown(x, y, button);
}

Expand All @@ -447,7 +447,7 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
#endif
for (int i = Components.size() - 1; i > -1 && !halt; --i)
{
if (!Components[i]->Locked && Components[i]->Visible)
if (Components[i]->Enabled && Components[i]->Visible)
{
Point local(x - Components[i]->Position.X, y - Components[i]->Position.Y);
Point a(local.X - dx, local.Y - dy);
Expand All @@ -469,7 +469,8 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
{
Components[i]->OnMouseEnter(local.X, local.Y);
}
hoverComponent = Components[i];
if (Components[i]->Enabled)
hoverComponent = Components[i];
}
else if (!halt)
{
Expand Down Expand Up @@ -503,7 +504,7 @@ void Window::DoMouseUp(int x_, int y_, unsigned button)
//on mouse unclick
for (int i = Components.size() - 1; i >= 0 && !halt; --i)
{
if (!Components[i]->Locked && Components[i]->Visible)
if (Components[i]->Enabled && Components[i]->Visible)
{
if (x >= Components[i]->Position.X && y >= Components[i]->Position.Y && x < Components[i]->Position.X + Components[i]->Size.X && y < Components[i]->Position.Y + Components[i]->Size.Y)
{
Expand All @@ -516,7 +517,7 @@ void Window::DoMouseUp(int x_, int y_, unsigned button)
//on mouse up
for (int i = Components.size() - 1; i >= 0 && !halt; --i)
{
if (!Components[i]->Locked && Components[i]->Visible)
if (Components[i]->Enabled && Components[i]->Visible)
Components[i]->OnMouseUp(x, y, button);
}

Expand All @@ -539,7 +540,7 @@ void Window::DoMouseWheel(int x_, int y_, int d)
{
if (x >= Components[i]->Position.X && y >= Components[i]->Position.Y && x < Components[i]->Position.X + Components[i]->Size.X && y < Components[i]->Position.Y + Components[i]->Size.Y)
{
if (!Components[i]->Locked && Components[i]->Visible)
if (Components[i]->Enabled && Components[i]->Visible)
Components[i]->OnMouseWheelInside(x - Components[i]->Position.X, y - Components[i]->Position.Y, d);
break;
}
Expand All @@ -548,7 +549,7 @@ void Window::DoMouseWheel(int x_, int y_, int d)
//on mouse wheel
for (int i = Components.size() - 1; i >= 0 && !halt; --i)
{
if (!Components[i]->Locked && Components[i]->Visible)
if (Components[i]->Enabled && Components[i]->Visible)
Components[i]->OnMouseWheel(x - Components[i]->Position.X, y - Components[i]->Position.Y, d);
}

Expand Down

0 comments on commit 15537d4

Please sign in to comment.