Update of /cvsroot/planeshift/planeshift/src/common/paws In directory sc8-pr-cvs1:/tmp/cvs-serv1767/src/common/paws Modified Files: pawscrollbar.cpp pawscrollbar.h pawsmanager.cpp pawstextbox.cpp pawstextbox.h pawswidget.cpp pawswidget.h Log Message: Fixed up the chat text box a bit. Still a problem of the thumb in the scroll bar disappearing on a resize though. Index: pawscrollbar.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/paws/pawscrollbar.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pawscrollbar.cpp 14 Dec 2003 19:24:07 -0000 1.5 --- pawscrollbar.cpp 21 Dec 2003 06:54:18 -0000 1.6 *************** *** 158,165 **** thumb->SetBackground(THUMB_IMAGE); thumb->SetID(SCROLL_THUMB); ! return true; } void pawsScrollBar::SetThumbPos() { --- 158,170 ---- thumb->SetBackground(THUMB_IMAGE); thumb->SetID(SCROLL_THUMB); ! return true; } + void pawsScrollBar::StopResize() + { + SetThumbPos(); + } + void pawsScrollBar::SetThumbPos() { *************** *** 183,190 **** --- 188,197 ---- screenFrame.ymin); else + { thumb->MoveTo(screenFrame.xmin + (screenFrame.Width()-thumb->ScreenFrame().Width()) / 2, screenFrame.ymin+BUTTON_SIZE + int(currentValue/maxValue*(screenFrame.Height()-3*BUTTON_SIZE))); + } } } *************** *** 314,317 **** --- 321,325 ---- void pawsScrollBar::Draw() { + if (mouseIsMovingThumb && maxValue>0) MoveThumbToMouse(); *************** *** 320,325 **** if ( mouseDown && (clock->GetCurrentTicks() - scrollTicks > SCROLL_TICKS )) ! OnButtonPressed(lastButton, lastModifiers, lastWidget); ! } --- 328,332 ---- if ( mouseDown && (clock->GetCurrentTicks() - scrollTicks > SCROLL_TICKS )) ! OnButtonPressed(lastButton, lastModifiers, lastWidget); } Index: pawscrollbar.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/paws/pawscrollbar.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** pawscrollbar.h 14 Dec 2003 19:24:07 -0000 1.6 --- pawscrollbar.h 21 Dec 2003 06:54:18 -0000 1.7 *************** *** 87,90 **** --- 87,91 ---- virtual bool OnGainFocus( bool notifyParent = true ) {return false;} + virtual void StopResize(); protected: /** Sets position of thumb on screen according to currentValue */ Index: pawsmanager.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/paws/pawsmanager.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** pawsmanager.cpp 7 Dec 2003 20:43:54 -0000 1.8 --- pawsmanager.cpp 21 Dec 2003 06:54:18 -0000 1.9 *************** *** 263,266 **** --- 263,267 ---- if ( resizingWidget ) { + resizingWidget->StopResize(); resizingWidget = NULL; return true; Index: pawstextbox.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/paws/pawstextbox.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** pawstextbox.cpp 23 Nov 2003 19:57:53 -0000 1.7 --- pawstextbox.cpp 21 Dec 2003 06:54:18 -0000 1.8 *************** *** 155,159 **** :pawsWidget( manager ) { ! topLine = 0; } --- 155,159 ---- :pawsWidget( manager ) { ! topLine = 0; } *************** *** 221,224 **** --- 221,234 ---- } + void pawsMessageTextBox::StopResize() + { + pawsWidget::StopResize(); + adjusted.Empty(); + for ( int x = 0; x < messages.Length(); x++ ) + { + SplitMessage( messages[x]->text, messages[x]->colour ); + } + } + void pawsMessageTextBox::OnResize() { *************** *** 230,242 **** maxLines = (screenFrame.Height()-borderOffSize-rest) / lineHeight; // Re adjust the top line value ! topLine = messages.Length() - maxLines; if ( topLine < 0 ) topLine = 0; ! scrollBar->SetMaxValue( (float)(messages.Length()-maxLines) ); scrollBar->SetCurrentValue( (float)topLine ); ! if ( maxLines < messages.Length() ) { scrollBar->Show(); --- 240,253 ---- maxLines = (screenFrame.Height()-borderOffSize-rest) / lineHeight; + // Re adjust the top line value ! topLine = adjusted.Length() - maxLines; if ( topLine < 0 ) topLine = 0; ! scrollBar->SetMaxValue( (float)(adjusted.Length()-maxLines) ); scrollBar->SetCurrentValue( (float)topLine ); ! if ( maxLines < adjusted.Length() ) { scrollBar->Show(); *************** *** 244,248 **** } else ! scrollBar->Hide(); } --- 255,259 ---- } else ! scrollBar->Hide(); } *************** *** 252,338 **** pawsWidget::Draw(); ! ClipToParent(); ! ! int linesDraw = 0; ! for ( int x = topLine; x < messages.Length(); x++ ) ! { ! const char* message = messages[x]->text; ! linesDraw = RenderMessage( message, linesDraw, messages[x]->colour ); ! ! if ( linesDraw == -1 ) return; ! } ! } ! ! int pawsMessageTextBox::RenderMessage( const char* message, int startLine, int colour ) ! { ! csString data( message ); ! csString nextLine( message ); ! ! bool messageComplete = false; ! int lines = startLine; ! ! // Check for border ! int max = 0; ! if ( border ) ! max = 8; ! ! int offSet = max / 2; ! if ( scrollBar->IsVisible() ) ! max += 36; ! ! while ( !messageComplete ) ! { ! size_t maxlen = GetFont()->GetLength( nextLine , screenFrame.Width() - max ); ! if ( maxlen == nextLine.Length() ) ! { ! if ( lines+1 > maxLines ) ! return -1; ! graphics2D->Write( GetFont(), ! screenFrame.xmin + offSet, ! screenFrame.ymin + lines*lineHeight, ! colour, ! -1, ! (const char*)nextLine ); ! ! return ++lines; } ! ! size_t checkForSpace = maxlen; ! char c = nextLine[checkForSpace]; ! while ( c != ' ' ) ! { ! if ( checkForSpace == 0 ) ! break; ! checkForSpace--; ! ! c = nextLine[checkForSpace]; ! } ! ! csString thisLine; ! if (!checkForSpace) ! checkForSpace = maxlen; ! thisLine.Replace( nextLine, checkForSpace ); ! thisLine.Append("\0"); ! ! nextLine.Replace( &nextLine[checkForSpace] ); ! ! graphics2D->Write( GetFont(), ! screenFrame.xmin, ! screenFrame.ymin + lines*lineHeight, ! colour, ! -1, ! (const char*)thisLine ); ! ! lines++; ! if ( lines+1 > maxLines ) ! return -1; ! } ! ! return 0; } bool pawsMessageTextBox::SelfPopulate( iDocumentNode *node) { --- 263,289 ---- pawsWidget::Draw(); ! ClipToParent(); ! ! int yPos = 0; + if ( topLine < 0 ) + topLine = 0; ! for ( int x = topLine; x < (topLine+maxLines); x++ ) ! { ! if ( x < adjusted.Length() ) ! { graphics2D->Write( GetFont(), ! screenFrame.xmin, ! screenFrame.ymin + yPos*lineHeight, ! adjusted[x]->colour, ! -1, ! (const char*)adjusted[x]->text ); ! yPos++; } ! } } + bool pawsMessageTextBox::SelfPopulate( iDocumentNode *node) { *************** *** 347,375 **** void pawsMessageTextBox::AddMessage( const char* data, int msgColour ) ! { MessageLine * msg = new MessageLine; msg->text = data; ! if ( msgColour != -1 ) msg->colour = msgColour; ! else msg->colour = GetFontColour(); ! messages.Push(msg); ! topLine = messages.Length() - maxLines; ! if ( topLine < 0 ) ! topLine = 0; ! ! scrollBar->SetMaxValue( (float)(messages.Length()-maxLines) ); ! scrollBar->SetCurrentValue( (float)topLine ); ! if ( messages.Length() > maxLines ) scrollBar->Show(); else scrollBar->Hide(); } bool pawsMessageTextBox::OnScroll( int direction, pawsScrollBar* widget ) ! { topLine = (int)widget->GetCurrentValue(); return true; --- 298,390 ---- void pawsMessageTextBox::AddMessage( const char* data, int msgColour ) ! { ! // Add it to the main message buffer. MessageLine * msg = new MessageLine; + int colour; + msg->text = data; ! if ( msgColour != -1 ) ! colour = msgColour; ! else ! colour = GetFontColour(); ! msg->colour = colour; ! messages.Push(msg); + ! SplitMessage( data, colour ); ! ! if ( adjusted.Length() > maxLines ) scrollBar->Show(); else scrollBar->Hide(); + + + scrollBar->SetMaxValue( (float)(adjusted.Length()-maxLines) ); + scrollBar->SetCurrentValue( (float)adjusted.Length() - maxLines ); + topLine = adjusted.Length() - maxLines; + if ( topLine < 0 ) + topLine = 0; } + void pawsMessageTextBox::SplitMessage( const char* newText, int colour ) + { + int maxWidth; + int maxHeight; + + GetFont()->GetMaxSize( maxWidth, maxHeight ); + + char* dummy = new char[strlen( newText ) + 1]; + char* head = dummy; + + strcpy( dummy, newText ); + + int offSet = 36; + + while ( dummy ) + { + /// See how many characters can be drawn on a single line. + int canDrawLength = GetFont()->GetLength( dummy, screenFrame.Width()-offSet ); + + /// If it can fit the entire string then return. + if ( canDrawLength == (int)strlen( dummy ) ) + { + csString temp( dummy ); + MessageLine* msgLine = new MessageLine; + msgLine->text = temp; + msgLine->colour = colour; + adjusted.Push( msgLine ); + break; + } + // We have to push in a new line to the lines bit. + else + { + // Find out the nearest white space to break the line. + int index = canDrawLength; + + while ( index > 0 && dummy[index] != ' ' ) + { + index--; + } + + // Index now points to the whitespace line so we can break it here. + + csString test; + test.Append( dummy, index ); + dummy+=index; + MessageLine* msgLine = new MessageLine; + msgLine->text = test; + msgLine->colour = colour; + adjusted.Push( msgLine ); + } + } + + delete head; + } bool pawsMessageTextBox::OnScroll( int direction, pawsScrollBar* widget ) ! { topLine = (int)widget->GetCurrentValue(); return true; Index: pawstextbox.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/paws/pawstextbox.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** pawstextbox.h 18 Nov 2003 10:49:16 -0000 1.3 --- pawstextbox.h 21 Dec 2003 06:54:18 -0000 1.4 *************** *** 113,117 **** virtual void OnResize(); ! virtual bool OnScroll( int direction, pawsScrollBar* widget ); --- 113,117 ---- virtual void OnResize(); ! virtual void StopResize(); virtual bool OnScroll( int direction, pawsScrollBar* widget ); *************** *** 126,129 **** --- 126,135 ---- /// List of messages this box has. csArray<MessageLine*> messages; + + //void AdjustMessages(); + + void SplitMessage( const char* text, int colour ); + + csPDelArray<MessageLine> adjusted; int lineHeight; *************** *** 133,136 **** --- 139,143 ---- pawsScrollBar* scrollBar; + }; Index: pawswidget.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/paws/pawswidget.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** pawswidget.cpp 11 Dec 2003 03:05:07 -0000 1.11 --- pawswidget.cpp 21 Dec 2003 06:54:18 -0000 1.12 *************** *** 463,466 **** --- 463,467 ---- Resize(); + StopResize(); return true; } *************** *** 1191,1194 **** --- 1192,1202 ---- } + void pawsWidget::StopResize() + { + for ( int x = 0; x < children.Length(); x++ ) + { + children[x]->StopResize(); + } + } void pawsWidget::Resize( int deltaX, int deltaY, int flags ) Index: pawswidget.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/paws/pawswidget.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** pawswidget.h 14 Dec 2003 19:24:07 -0000 1.9 --- pawswidget.h 21 Dec 2003 06:54:18 -0000 1.10 *************** *** 235,238 **** --- 235,241 ---- virtual void OnResize() { } + + /// Called once the mouse up is done after resizing a widget. + virtual void StopResize(); virtual int GetBorderColour(int which); |