[solved]Scrollbar problem

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

K0h4n
Just popping in
Just popping in
Posts: 14
Joined: Sun Apr 06, 2008 15:21

[solved]Scrollbar problem

Postby K0h4n » Thu Jul 10, 2008 08:57

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
Last edited by K0h4n on Thu Jul 10, 2008 16:11, edited 1 time in total.

K0h4n
Just popping in
Just popping in
Posts: 14
Joined: Sun Apr 06, 2008 15:21

Postby K0h4n » Thu Jul 10, 2008 16:10

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...


Return to “Help”

Who is online

Users browsing this forum: No registered users and 7 guests