void IGUIScrollBar::HandleMessage(SGUIMessage &Message) { switch (Message.type) { case GUIM_MOUSE_MOTION: { // TODO Gee: Optimizations needed! CPos mouse = m_pHostObject->GetMousePos(); // If bar is being dragged if (m_BarPressed) { SetPosFromMousePos(mouse); UpdatePosBoundaries(); } // check if components are being hovered m_BarHovered = GetBarRect().PointInside(mouse); m_ButtonMinusHovered = HoveringButtonMinus(mouse); m_ButtonPlusHovered = HoveringButtonPlus(mouse); if (!m_ButtonMinusHovered) m_ButtonMinusPressed = false; if (!m_ButtonPlusHovered) m_ButtonPlusPressed = false; break; } case GUIM_MOUSE_PRESS_LEFT: { if (!m_pHostObject) break; CPos mouse = m_pHostObject->GetMousePos(); // if bar is pressed if (GetBarRect().PointInside(mouse)) { m_BarPressed = true; m_BarPressedAtPos = mouse; m_PosWhenPressed = m_Pos; } else // if button-minus is pressed if (m_ButtonMinusHovered) { m_ButtonMinusPressed = true; ScrollMinus(); } else // if button-plus is pressed if (m_ButtonPlusHovered) { m_ButtonPlusPressed = true; ScrollPlus(); } else // Pressing the background of the bar, to scroll // notice the if-sentence alone does not admit that, // it must be after the above if/elses { if (GetOuterRect().PointInside(mouse)) { // Scroll plus or minus a lot, this might change, it doesn't // have to be fancy though. if (mouse.y < GetBarRect().top) ScrollMinusPlenty(); else ScrollPlusPlenty(); // Simulate mouse movement to see if bar now is hovered SGUIMessage msg(GUIM_MOUSE_MOTION); HandleMessage(msg); } } break; } case GUIM_MOUSE_RELEASE_LEFT: { m_ButtonMinusPressed = false; m_ButtonPlusPressed = false; break; } case GUIM_MOUSE_WHEEL_UP: { ScrollMinus(); // Since the scroll was changed, let's simulate a mouse movement // to check if scrollbar now is hovered SGUIMessage msg(GUIM_MOUSE_MOTION); HandleMessage(msg); break; } case GUIM_MOUSE_WHEEL_DOWN: { ScrollPlus(); // Since the scroll was changed, let's simulate a mouse movement // to check if scrollbar now is hovered SGUIMessage msg(GUIM_MOUSE_MOTION); HandleMessage(msg); break; } default: break; } }
void CGUIScrollBarVertical::Draw() { if (!GetStyle()) { LOGWARNING("Attempt to draw scrollbar without a style."); return; } if (GetGUI() && IsVisible()) { CRect outline = GetOuterRect(); // Draw background GetGUI()->DrawSprite(GetStyle()->m_SpriteBackVertical, 0, m_Z+0.1f, CRect(outline.left, outline.top+(GetStyle()->m_UseEdgeButtons?GetStyle()->m_Width:0), outline.right, outline.bottom-(GetStyle()->m_UseEdgeButtons?GetStyle()->m_Width:0)) ); if (GetStyle()->m_UseEdgeButtons) { // Get Appropriate sprites const CGUISpriteInstance* button_top; const CGUISpriteInstance* button_bottom; // figure out what sprite to use for top button if (m_ButtonMinusHovered) { if (m_ButtonMinusPressed) button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopPressed, GetStyle()->m_SpriteButtonTop); else button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop); } else button_top = &GetStyle()->m_SpriteButtonTop; // figure out what sprite to use for bottom button if (m_ButtonPlusHovered) { if (m_ButtonPlusPressed) button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomPressed, GetStyle()->m_SpriteButtonBottom); else button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom); } else button_bottom = &GetStyle()->m_SpriteButtonBottom; // Draw top button GetGUI()->DrawSprite(*button_top, 0, m_Z+0.2f, CRect(outline.left, outline.top, outline.right, outline.top+GetStyle()->m_Width) ); // Draw bottom button GetGUI()->DrawSprite(*button_bottom, 0, m_Z+0.2f, CRect(outline.left, outline.bottom-GetStyle()->m_Width, outline.right, outline.bottom) ); } // Draw bar GetGUI()->DrawSprite(GetStyle()->m_SpriteBarVertical, 0, m_Z + 0.2f, GetBarRect()); } }