diff options
| author | oy <Tom_Adams@web.de> | 2010-09-30 01:13:12 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2010-09-30 01:13:12 +0200 |
| commit | 2f388139c1e46d8cde32bd446b880e4225b06b35 (patch) | |
| tree | ce29d5436e96edd7e822fcc875c2cf44b7fd146c /src/game/client/components/menus_demo.cpp | |
| parent | 68851630caecac3a886f9ec7bb5a43b6b05736d4 (diff) | |
| download | zcatch-2f388139c1e46d8cde32bd446b880e4225b06b35.tar.gz zcatch-2f388139c1e46d8cde32bd446b880e4225b06b35.zip | |
fixed auto-scrolling in server browser and listbox
Diffstat (limited to 'src/game/client/components/menus_demo.cpp')
| -rw-r--r-- | src/game/client/components/menus_demo.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/game/client/components/menus_demo.cpp b/src/game/client/components/menus_demo.cpp index 470a2529..e08114ad 100644 --- a/src/game/client/components/menus_demo.cpp +++ b/src/game/client/components/menus_demo.cpp @@ -370,15 +370,24 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(void *pId, bool Selected) if(NewIndex > -1 && NewIndex < gs_ListBoxNumItems) { // scroll - int NumViewable = (int)(gs_ListBoxOriginalView.h/gs_ListBoxRowHeight) + 1; - int ScrollNum = (gs_ListBoxNumItems+gs_ListBoxItemsPerRow-1)/gs_ListBoxItemsPerRow-NumViewable+1; - if(ScrollNum > 0 && NewIndex/gs_ListBoxItemsPerRow-gs_ListBoxSelectedIndex/gs_ListBoxItemsPerRow) + float Offset = (NewIndex-gs_ListBoxNewSelected)*gs_ListBoxRowHeight; + int Scroll = gs_ListBoxOriginalView.y > Item.m_Rect.y+Offset ? -1 : + gs_ListBoxOriginalView.y+gs_ListBoxOriginalView.h < Item.m_Rect.y+Item.m_Rect.h+Offset ? 1 : 0; + if(Scroll) { - // TODO: make the scrolling better - if(NewIndex - gs_ListBoxSelectedIndex > 0) - gs_ListBoxScrollValue += 1.0f/ScrollNum; + int NumViewable = (int)(gs_ListBoxOriginalView.h/gs_ListBoxRowHeight) + 1; + int ScrollNum = (gs_ListBoxNumItems+gs_ListBoxItemsPerRow-1)/gs_ListBoxItemsPerRow-NumViewable+1; + if(Scroll < 0) + { + int Num = (gs_ListBoxOriginalView.y-Item.m_Rect.y-Offset+gs_ListBoxRowHeight-1.0f)/(gs_ListBoxItemsPerRow*gs_ListBoxRowHeight); + gs_ListBoxScrollValue -= (1.0f/ScrollNum)*Num; + } else - gs_ListBoxScrollValue -= 1.0f/ScrollNum; + { + int Num = (Item.m_Rect.y+Item.m_Rect.h+Offset-(gs_ListBoxOriginalView.y+gs_ListBoxOriginalView.h)+gs_ListBoxRowHeight-1.0f)/ + (gs_ListBoxItemsPerRow*gs_ListBoxRowHeight); + gs_ListBoxScrollValue += (1.0f/ScrollNum)*Num; + } if(gs_ListBoxScrollValue < 0.0f) gs_ListBoxScrollValue = 0.0f; if(gs_ListBoxScrollValue > 1.0f) gs_ListBoxScrollValue = 1.0f; } |