style improvements in Window.cpp / Window.h

This commit is contained in:
jacob1 2015-07-09 22:59:01 -04:00
parent f65c4363b1
commit 67bcd5e863
2 changed files with 125 additions and 152 deletions
src/gui/interface

View File

@ -36,7 +36,6 @@ Window::~Window()
void Window::AddComponent(Component* c) void Window::AddComponent(Component* c)
{ {
// TODO: do a check if component was already added?
if (c->GetParentWindow() == NULL) if (c->GetParentWindow() == NULL)
{ {
c->SetParentWindow(this); c->SetParentWindow(this);
@ -48,7 +47,7 @@ void Window::AddComponent(Component* c)
} }
else else
{ {
//Component already has a state, don't sad it //Component already in a window
} }
} }
@ -121,32 +120,27 @@ void Window::FocusComponent(Component* c)
void Window::DoExit() void Window::DoExit()
{ {
OnExit(); OnExit();
} }
void Window::DoInitialized() void Window::DoInitialized()
{ {
OnInitialized(); OnInitialized();
} }
void Window::DoBlur() void Window::DoBlur()
{ {
OnBlur(); OnBlur();
} }
void Window::DoFocus() void Window::DoFocus()
{ {
OnFocus(); OnFocus();
} }
void Window::DoDraw() void Window::DoDraw()
{ {
OnDraw(); OnDraw();
//draw
for (int i = 0, sz = Components.size(); i < sz; ++i) for (int i = 0, sz = Components.size(); i < sz; ++i)
if (Components[i]->Visible && ((Components[i] != focusedComponent_ && Components[i] != hoverComponent) || Components[i]->GetParent())) if (Components[i]->Visible && ((Components[i] != focusedComponent_ && Components[i] != hoverComponent) || Components[i]->GetParent()))
{ {
@ -157,13 +151,12 @@ void Window::DoDraw()
} }
else else
{ {
if( Components[i]->Position.X+Position.X + Components[i]->Size.X >= 0 && if (scrpos.X + Components[i]->Size.X >= 0 &&
Components[i]->Position.Y+Position.Y + Components[i]->Size.Y >= 0 && scrpos.Y + Components[i]->Size.Y >= 0 &&
Components[i]->Position.X+Position.X < ui::Engine::Ref().GetWidth() && scrpos.X < ui::Engine::Ref().GetWidth() &&
Components[i]->Position.Y+Position.Y < ui::Engine::Ref().GetHeight() ) scrpos.Y < ui::Engine::Ref().GetHeight())
{ {
Point scrpos(Components[i]->Position.X + Position.X, Components[i]->Position.Y + Position.Y); Components[i]->Draw(scrpos);
Components[i]->Draw( Point(scrpos) );
} }
} }
#ifdef DEBUG #ifdef DEBUG
@ -456,8 +449,8 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
{ {
if (!Components[i]->Locked && Components[i]->Visible) if (!Components[i]->Locked && Components[i]->Visible)
{ {
Point local (x - Components[i]->Position.X, y - Components[i]->Position.Y) Point local(x - Components[i]->Position.X, y - Components[i]->Position.Y);
, a (local.X - dx, local.Y - dy); Point a(local.X - dx, local.Y - dy);
Components[i]->OnMouseMoved(local.X, local.Y, dx, dy); Components[i]->OnMouseMoved(local.X, local.Y, dx, dy);
@ -469,8 +462,7 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
Components[i]->OnMouseMovedInside(local.X, local.Y, dx, dy); Components[i]->OnMouseMovedInside(local.X, local.Y, dx, dy);
// entering? // entering?
if(!( if (!(a.X >= 0 &&
a.X >= 0 &&
a.Y >= 0 && a.Y >= 0 &&
a.X < Components[i]->Size.X && a.X < Components[i]->Size.X &&
a.Y < Components[i]->Size.Y )) a.Y < Components[i]->Size.Y ))

View File

@ -12,12 +12,12 @@ enum ChromeStyle
{ {
None, Title, Resizable None, Title, Resizable
}; };
//class State;
class Engine; class Engine;
class Component; class Component;
class Button; class Button;
/* class State /* class Window
* *
* A UI state. Contains all components. * A UI state. Contains all components.
*/ */
@ -35,19 +35,19 @@ enum ChromeStyle
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 window
void AddComponent(Component* c); void AddComponent(Component* c);
// Get the number of components this state has. // Get the number of components this window has.
unsigned GetComponentCount(); unsigned GetComponentCount();
// Get component by index. (See GetComponentCount()) // Get component by index. (See GetComponentCount())
Component* GetComponent(unsigned idx); Component* GetComponent(unsigned idx);
// Remove a component from state. NOTE: This DOES NOT free component from memory. // Remove a component from window. NOTE: This DOES NOT free component from memory.
void RemoveComponent(Component* c); void RemoveComponent(Component* c);
// Remove a component from state. NOTE: This WILL free component from memory. // Remove a component from window. NOTE: This WILL free component from memory.
void RemoveComponent(unsigned idx); void RemoveComponent(unsigned idx);
virtual void ToolTip(ui::Point senderPosition, std::string toolTip) {} virtual void ToolTip(ui::Point senderPosition, std::string toolTip) {}
@ -113,24 +113,5 @@ enum ChromeStyle
bool stop; bool stop;
}; };
/*class Window : public State
{
private:
ChromeStyle chrome;
public:
Window(Point _position, Point _size);
Point Position;
Point Size;
virtual void DoTick(float dt);
virtual void DoDraw();
virtual void DoMouseMove(int x, int y, int dx, int dy);
virtual void DoMouseDown(int x, int y, unsigned button);
virtual void DoMouseUp(int x, int y, unsigned button);
virtual void DoMouseWheel(int x, int y, int d);
};*/
} }
#endif // WINDOW_H #endif // WINDOW_H