Page 1 of 1

[solved]Scrollbar problem

Posted: Thu Jul 10, 2008 08:57
by K0h4n
i'm trying to create a chat box for a game
and i want to create the scroll bar to point at the end of the chat box and stay at the current point if the scroll bar are moved to the other position
(i'm using list box as a chat box)
the scroll bar then will be locked again once the user drag it to the end
the problem is i dont know how to get the maximum number of the scroll bar position
i'm using these code to get the maximum number of the scrollbar position and compare it with current position (if not same then the bar is moved to another place):

Code: Select all

bar->getDocumentSize() - bar->getPageSize()


below is the snippet of the code

Code: Select all

bool handle_GameRoomChat(const CEGUI::EventArgs& args){
      using namespace CEGUI;

      // initialize window manager
      WindowManager *wmgr = WindowManager::getSingletonPtr();

      //initialize chat window
      Listbox* chatLog = static_cast<Listbox*> (wmgr->getWindow((utf8*)"GameRoom/ChatLog"));
      Window *chat = wmgr->getWindow((utf8*)"GameRoom/ChatInput");
      
      ListboxTextItem* chatItem;

      if(!chat->getText().empty()){
         bool notMove = true;
         
         Scrollbar *bar = chatLog->getVertScrollbar();

         if(bar->getScrollPosition() < (bar->getDocumentSize() - bar->getPageSize()))
            notMove = false;

         chatItem = new ListboxTextItem(chat->getText());
         chatLog->addItem(chatItem);
         
         if(notMove)
            bar->setScrollPosition(bar->getDocumentSize() - bar->getPageSize());
      }
      
      chat->setText("");

      return true;
   }


is not really crucial in the system but i think it is kinda annoying while you scroll up want to read the chat history and suddenly someone chat with you and scroll you down

any help is appreciated
thank you

Posted: Thu Jul 10, 2008 16:10
by K0h4n
omg
now i know how to fix it
here is the code to solve it

Code: Select all

bool handle_GameRoomChat(const CEGUI::EventArgs& args){
      using namespace CEGUI;

      // initialize window manager
      WindowManager *wmgr = WindowManager::getSingletonPtr();

      //initialize chat window
      Listbox* chatLog = static_cast<Listbox*> (wmgr->getWindow((utf8*)"GameRoom/ChatLog"));
      Window *chat = wmgr->getWindow((utf8*)"GameRoom/ChatInput");
      
      ListboxTextItem* chatItem;

      if(!chat->getText().empty()){
         
         bool scrolled = false;

         Scrollbar *bar = chatLog->getVertScrollbar();
         
         if(bar->getScrollPosition() != (bar->getDocumentSize() - bar->getPageSize()) &&
            (bar->getDocumentSize() - bar->getPageSize()) > 0)
            scrolled = true;

         chatItem = new ListboxTextItem(chat->getText());
         chatLog->addItem(chatItem);

         if(!scrolled && (bar->getDocumentSize() - bar->getPageSize()) > 0)
            bar->setScrollPosition(bar->getDocumentSize() - bar->getPageSize());
      }
      
      chat->setText("");

      return true;
   }


i'm happy now cause i learn something new today
debugging
XD
thx to the problem
hehehe...