Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 10, 2010, 3:18:14 PM (15 years ago)
Author:
smerkli
Message:

Scrolling chat now works, discovered delete-button bug, fixing it now.

Location:
code/branches/chat2/src/orxonox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/chat2/src/orxonox/ChatInputHandler.cc

    r6870 r6876  
    4444  /* singleton */
    4545  ManageScopedSingleton( ChatInputHandler, ScopeID::Graphics, false );
     46
     47  /* add commands to console */
    4648  SetConsoleCommandAlias( ChatInputHandler, activate_static, "startchat",
    4749    true );
     
    4951    "startchat_small", true );
    5052
    51 
    5253  /* constructor */
    5354  ChatInputHandler::ChatInputHandler()
     
    5859    /* create necessary objects */
    5960    this->inpbuf = new InputBuffer();
     61    this->disp_offset = 0;
    6062    assert( this->inpbuf != NULL );
    6163
     
    133135    InputManager::getInstance().leaveState("chatinput");
    134136
    135     /* MARK add un-spawning of chat widget stuff here. */
     137    /* un-spawning of chat widget stuff */
    136138    GUIManager::getInstance().hideGUI( "ChatBox" );
    137139    GUIManager::getInstance().hideGUI( "ChatBox-inputonly" );
    138140  }
    139141
     142  void ChatInputHandler::sub_adjust_dispoffset( int maxlen, int cursorpos, int inplen )
     143  {
     144    /* already start offsetting 5 characters before end */
     145    if( cursorpos+5 > maxlen )
     146    {
     147      /* always stay 5 characters ahead of end, looks better */
     148      ((disp_offset = cursorpos-maxlen+5) >= 0) ? 1 : disp_offset = 0;
     149
     150      /* enforce visibility of cursor */
     151      (disp_offset > cursorpos ) ? disp_offset = 0 : 1;
     152    }
     153     
     154    /* make sure we don't die at substr */
     155    if( inplen <= disp_offset ) disp_offset = 0;
     156  }
     157
    140158  /* callbacks for InputBuffer */
    141159  void ChatInputHandler::inputChanged()
     
    143161    /* update the cursor and the window */
    144162    std::string raw = this->inpbuf->get();
     163    int cursorpos = this->inpbuf->getCursorPosition();
    145164   
    146165    /* get string before cursor */
    147     std::string left = raw.substr( 0, this->inpbuf->getCursorPosition() );
     166    std::string left = raw.substr( 0, cursorpos );
    148167
    149168    /* see if there's a string after the cursor */
    150169    std::string right = "";
    151170    if( raw.length() >= left.length()+1 )
    152       right = raw.substr( this->inpbuf->getCursorPosition() );
     171      right = raw.substr( cursorpos );
    153172     
    154173    /* set the text */
    155     this->input->setProperty( "Text", left + "|" + right );
    156     this->inputonly->setProperty( "Text", left + "|" + right );
     174    std::string assembled = "$ " + left + "|" + right;
     175
     176    /* adjust curser position - magic number 5 for font width */
     177    sub_adjust_dispoffset( (this->input->getUnclippedInnerRect().getWidth()/6),
     178      cursorpos, assembled.length() );
     179    this->input->setProperty( "Text", assembled.substr( disp_offset ) );
     180
     181    /* reset display offset */
     182    disp_offset = 0;
     183
     184    /* adjust curser position - magic number 5 for font width */
     185    sub_adjust_dispoffset( (this->inputonly->getUnclippedInnerRect().getWidth()/6),
     186      cursorpos, assembled.length() );
     187    this->inputonly->setProperty( "Text", assembled.substr( disp_offset) );
     188
     189    /* reset display offset */
     190    disp_offset = 0;
    157191  }
    158192
  • code/branches/chat2/src/orxonox/ChatInputHandler.h

    r6870 r6876  
    6262       */
    6363      InputBuffer *inpbuf;
     64      int disp_offset, width;
    6465
    6566      /** input state */
     
    6869      /** setup input buffer, the constructor calls this */
    6970      void configureInputBuffer();
     71
     72      /** adjust display offset depending on cursor position */
     73      void sub_adjust_dispoffset( int maxlen, int cursorpos, int inplen );
    7074
    7175      /* singleton pointer */
Note: See TracChangeset for help on using the changeset viewer.