hovered / focused components are always drawn last

This commit is contained in:
jacob1 2015-07-09 22:52:34 -04:00
parent 85ce852cbc
commit f65c4363b1
3 changed files with 38 additions and 7 deletions

View File

@ -14,6 +14,7 @@ Window::Window(Point _position, Point _size):
okayButton(NULL), okayButton(NULL),
cancelButton(NULL), cancelButton(NULL),
focusedComponent_(NULL), focusedComponent_(NULL),
hoverComponent(NULL),
#ifdef DEBUG #ifdef DEBUG
debugMode(false), debugMode(false),
#endif #endif
@ -29,8 +30,6 @@ Window::~Window()
if( Components[i] ) if( Components[i] )
{ {
delete Components[i]; delete Components[i];
if(Components[i]==focusedComponent_)
focusedComponent_ = NULL;
} }
Components.clear(); Components.clear();
} }
@ -75,6 +74,8 @@ void Window::RemoveComponent(Component* c)
halt = true; halt = true;
if(Components[i]==focusedComponent_) if(Components[i]==focusedComponent_)
focusedComponent_ = NULL; focusedComponent_ = NULL;
if (Components[i] == hoverComponent)
hoverComponent = NULL;
Components.erase(Components.begin() + i); Components.erase(Components.begin() + i);
@ -102,6 +103,8 @@ void Window::RemoveComponent(unsigned idx)
// free component and remove it. // free component and remove it.
if(Components[idx]==focusedComponent_) if(Components[idx]==focusedComponent_)
focusedComponent_ = NULL; focusedComponent_ = NULL;
if (Components[idx] == hoverComponent)
hoverComponent = NULL;
delete Components[idx]; delete Components[idx];
Components.erase(Components.begin() + idx); Components.erase(Components.begin() + idx);
} }
@ -144,12 +147,12 @@ void Window::DoDraw()
{ {
OnDraw(); OnDraw();
//draw //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) 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); Components[i]->Draw(scrpos);
} }
else else
@ -177,6 +180,31 @@ void Window::DoDraw()
} }
#endif #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 #ifdef DEBUG
if(debugMode) if(debugMode)
{ {
@ -449,6 +477,7 @@ void Window::DoMouseMove(int x_, int y_, int dx, int dy)
{ {
Components[i]->OnMouseEnter(local.X, local.Y); Components[i]->OnMouseEnter(local.X, local.Y);
} }
hoverComponent = Components[i];
} }
else if(!halt) else if(!halt)
{ {

View File

@ -99,7 +99,8 @@ enum ChromeStyle
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {} 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) {} virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
std::vector<Component*> Components; std::vector<Component*> Components;
Component* focusedComponent_; Component *focusedComponent_;
Component *hoverComponent;
ChromeStyle chrome; ChromeStyle chrome;
#ifdef DEBUG #ifdef DEBUG

View File

@ -257,6 +257,7 @@ void ProfileActivity::ResizeArea()
{ {
int oldSize = scrollPanel->InnerSize.Y; int oldSize = scrollPanel->InnerSize.Y;
scrollPanel->InnerSize = ui::Point(Size.X, bio->Position.Y + bio->Size.Y + 10); 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) if (oldSize+scrollPanel->ViewportPosition.Y == scrollPanel->Size.Y)
scrollPanel->SetScrollPosition(scrollPanel->InnerSize.Y-scrollPanel->Size.Y); scrollPanel->SetScrollPosition(scrollPanel->InnerSize.Y-scrollPanel->Size.Y);
} }