Skip to content

Commit

Permalink
hovered / focused components are always drawn last
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Jul 10, 2015
1 parent 85ce852 commit f65c436
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
41 changes: 35 additions & 6 deletions src/gui/interface/Window.cpp
Expand Up @@ -14,6 +14,7 @@ Window::Window(Point _position, Point _size):
okayButton(NULL),
cancelButton(NULL),
focusedComponent_(NULL),
hoverComponent(NULL),
#ifdef DEBUG
debugMode(false),
#endif
Expand All @@ -29,8 +30,6 @@ Window::~Window()
if( Components[i] )
{
delete Components[i];
if(Components[i]==focusedComponent_)
focusedComponent_ = NULL;
}
Components.clear();
}
Expand Down Expand Up @@ -75,6 +74,8 @@ void Window::RemoveComponent(Component* c)
halt = true;
if(Components[i]==focusedComponent_)
focusedComponent_ = NULL;
if (Components[i] == hoverComponent)
hoverComponent = NULL;

Components.erase(Components.begin() + i);

Expand Down Expand Up @@ -102,6 +103,8 @@ void Window::RemoveComponent(unsigned idx)
// free component and remove it.
if(Components[idx]==focusedComponent_)
focusedComponent_ = NULL;
if (Components[idx] == hoverComponent)
hoverComponent = NULL;
delete Components[idx];
Components.erase(Components.begin() + idx);
}
Expand Down Expand Up @@ -144,12 +147,12 @@ void Window::DoDraw()
{
OnDraw();
//draw
for(int i = 0, sz = Components.size(); i < sz; ++i)
if(Components[i]->Visible)
for (int i = 0, sz = Components.size(); i < sz; ++i)
if (Components[i]->Visible && ((Components[i] != focusedComponent_ && Components[i] != hoverComponent) || Components[i]->GetParent()))
{
if(AllowExclusiveDrawing)
Point scrpos(Components[i]->Position.X + Position.X, Components[i]->Position.Y + Position.Y);
if (AllowExclusiveDrawing)
{
Point scrpos(Components[i]->Position.X + Position.X, Components[i]->Position.Y + Position.Y);
Components[i]->Draw(scrpos);
}
else
Expand Down Expand Up @@ -177,6 +180,31 @@ void Window::DoDraw()
}
#endif
}
// the component the mouse is hovering over and the focused component are always drawn last
if (hoverComponent && hoverComponent->Visible && hoverComponent->GetParent() == NULL)
{
Point scrpos(hoverComponent->Position.X + Position.X, hoverComponent->Position.Y + Position.Y);
if ((scrpos.X + hoverComponent->Size.X >= 0 &&
scrpos.Y + hoverComponent->Size.Y >= 0 &&
scrpos.X < ui::Engine::Ref().GetWidth() &&
scrpos.Y < ui::Engine::Ref().GetHeight()
) || AllowExclusiveDrawing)
{
hoverComponent->Draw(scrpos);
}
}
if (focusedComponent_ && focusedComponent_ != hoverComponent && focusedComponent_->Visible && focusedComponent_->GetParent() == NULL)
{
Point scrpos(focusedComponent_->Position.X + Position.X, focusedComponent_->Position.Y + Position.Y);
if ((scrpos.X + focusedComponent_->Size.X >= 0 &&
scrpos.Y + focusedComponent_->Size.Y >= 0 &&
scrpos.X < ui::Engine::Ref().GetWidth() &&
scrpos.Y < ui::Engine::Ref().GetHeight()
) || AllowExclusiveDrawing)
{
focusedComponent_->Draw(scrpos);
}
}
#ifdef DEBUG
if(debugMode)
{
Expand Down Expand Up @@ -449,6 +477,7 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
{
Components[i]->OnMouseEnter(local.X, local.Y);
}
hoverComponent = Components[i];
}
else if(!halt)
{
Expand Down
3 changes: 2 additions & 1 deletion src/gui/interface/Window.h
Expand Up @@ -99,7 +99,8 @@ enum ChromeStyle
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
std::vector<Component*> Components;
Component* focusedComponent_;
Component *focusedComponent_;
Component *hoverComponent;
ChromeStyle chrome;

#ifdef DEBUG
Expand Down
1 change: 1 addition & 0 deletions src/gui/profile/ProfileActivity.cpp
Expand Up @@ -257,6 +257,7 @@ void ProfileActivity::ResizeArea()
{
int oldSize = scrollPanel->InnerSize.Y;
scrollPanel->InnerSize = ui::Point(Size.X, bio->Position.Y + bio->Size.Y + 10);
// auto scroll as ScrollPanel size increases
if (oldSize+scrollPanel->ViewportPosition.Y == scrollPanel->Size.Y)
scrollPanel->SetScrollPosition(scrollPanel->InnerSize.Y-scrollPanel->Size.Y);
}
Expand Down

0 comments on commit f65c436

Please sign in to comment.