Index: data/gui/chat_basic.xml
===================================================================
--- data/gui/chat_basic.xml (revision 5445)
+++ data/gui/chat_basic.xml (working copy)
@@ -87,11 +87,12 @@
-
-
-
-
+
+
+
+
+
@@ -103,7 +104,7 @@
-
+
@@ -116,7 +117,7 @@
-
+
@@ -129,7 +130,7 @@
-
+
@@ -142,7 +143,7 @@
-
+
@@ -155,7 +156,7 @@
-
+
@@ -168,7 +169,7 @@
-
+
@@ -181,7 +182,7 @@
-
+
@@ -195,7 +196,7 @@
-
+
@@ -209,7 +210,7 @@
-
+
Index: src/common/paws/pawstextbox.h
===================================================================
--- src/common/paws/pawstextbox.h (revision 5445)
+++ src/common/paws/pawstextbox.h (working copy)
@@ -188,7 +188,6 @@
void AppendLastMessage( const char* data );
virtual void OnResize();
- virtual void Resize();
virtual bool OnScroll( int direction, pawsScrollBar* widget );
virtual bool OnMouseDown( int button, int modifiers, int x, int y );
@@ -219,7 +218,7 @@
/// Calculates value of the lineHeight attribute
void CalcLineHeight();
- csPDelArray adjusted;
+ csPDelArray messageLines;
int lineHeight;
size_t maxLines;
@@ -229,9 +228,14 @@
pawsScrollBar* scrollBar;
private:
+ void BeforeSetup();
+ void AfterSetup();
+ pawsScrollBar* GetScrollBar();
static const int INITOFFSET = 20;
void WriteMessageLine(MessageLine*& msgLine, csString text, int colour);
void WriteMessageSegment(MessageLine*& msgLine, csString text, int colour, int startPosition);
+ void ResizeMessage();
+ void AdjustScrollBar();
csString FindStringThatFits(csString stringBuffer, int canDrawLength);
};
Index: src/common/paws/pawscrollbar.cpp
===================================================================
--- src/common/paws/pawscrollbar.cpp (revision 5445)
+++ src/common/paws/pawscrollbar.cpp (working copy)
@@ -132,6 +132,15 @@
attr = node->GetAttribute("tick");
if (attr)
tickValue = attr->GetValueAsFloat();
+
+ attr = node->GetAttribute("width");
+ if (attr)
+ {
+ int width = attr->GetValueAsInt();;
+ upWidth = width;
+ downWidth = width;
+ defaultFrame.SetSize(width,defaultFrame.Height());
+ }
// up button settings
csRef upNode = node->GetNode("up");
@@ -168,7 +177,7 @@
// down button settings
csRef downNode = node->GetNode("down");
- if (upNode)
+ if (downNode)
{
attr = downNode->GetAttribute("grey");
if (attr)
@@ -255,16 +264,11 @@
}
}
-void pawsScrollBar::SetHorizontal (bool value)
-{
- horizontal = value;
- SetThumbLayout();
-}
-
bool pawsScrollBar::PostSetup()
{
// Create the scroll up/left button
upButton = new pawsButton;
+ upButton->SetName("pawscrollbar::pawsButton::up");
upButton->SetParent( this );
int flags;
if (!horizontal)
@@ -301,6 +305,7 @@
// Create the scroll down button.
downButton = new pawsButton;
+ downButton->SetName("pawscrollbar::pawsButton::down");
downButton->SetParent( this );
if (!horizontal)
{
@@ -367,6 +372,12 @@
SetButtonLayout();
}
+void pawsScrollBar::SetHorizontal (bool value)
+{
+ horizontal = value;
+ SetThumbLayout();
+}
+
void pawsScrollBar::SetThumbLayout()
{
int scrollBarSize = GetScrollBarSize();
@@ -400,6 +411,11 @@
}
}
+int pawsScrollBar::GetScrollBarSize()
+{
+ return horizontal ? screenFrame.Height() : screenFrame.Width();
+}
+
bool pawsScrollBar::OnMouseDown( int button, int modifiers, int x, int y )
{
if (button == csmbWheelUp)
@@ -586,11 +602,6 @@
this->limited = limited;
}
-int pawsScrollBar::GetScrollBarSize()
-{
- return horizontal ? screenFrame.Height() : screenFrame.Width();
-}
-
void pawsScrollBar::SetButtonLayout()
{
int scrollBarSize = GetScrollBarSize();
@@ -603,11 +614,24 @@
if (downHeight == 0)
downHeight = scrollBarSize;
- if (upButton)
- upButton->SetRelativeFrame(upOffsetx, upOffsety, upWidth, upHeight);
+
+ if(!horizontal)
+ {
+ if (upButton)
+ upButton->SetRelativeFrame(upOffsetx, upOffsety, upWidth, upHeight);
- if (downButton)
- downButton->SetRelativeFrame(defaultFrame.Width()-downWidth-downOffsetx, defaultFrame.Height()-downHeight-downOffsety, downWidth, downHeight);
+ if (downButton)
+ downButton->SetRelativeFrame(defaultFrame.Width()-downWidth-downOffsetx, defaultFrame.Height()-downHeight-downOffsety, downWidth, downHeight);
+// downButton->SetRelativeFrame(downOffsety, defaultFrame.Height()-downHeight-downOffsety, downWidth, downHeight);
+ }
+ else
+ {
+ if (upButton)
+ upButton->SetRelativeFrame(upOffsetx, upOffsety, upWidth, upHeight);
+
+ if (downButton)
+ downButton->SetRelativeFrame(defaultFrame.Width()-downWidth-downOffsetx, defaultFrame.Height()-downHeight-downOffsety, downWidth, downHeight);
+ }
}
int pawsScrollBar::GetThumbScaleLength()
Index: src/common/paws/pawswidget.cpp
===================================================================
--- src/common/paws/pawswidget.cpp (revision 5445)
+++ src/common/paws/pawswidget.cpp (working copy)
@@ -757,6 +757,9 @@
if ( ! LoadAttributes(node) )
return false;
+ if ( ! LoadChildren(node) )
+ return false;
+
// Call the setup for this widget.
if ( !Setup( node ) )
{
@@ -767,10 +770,6 @@
//if (name=="ChatWindow")
// printf("Chat found.");
- if ( ! LoadChildren(node) )
- return false;
-
-
// load scripts after we've loaded all children
if (!LoadEventScripts(node))
return false;
@@ -850,6 +849,7 @@
}
widget = PawsManager::GetSingleton().CreateWidget( factory );
+ widget->SetName("pawsWidget::"+factory);
CS_ASSERT_MSG("Creating widget from factory name failed.", widget!=NULL);
AddChild( widget );
@@ -862,7 +862,6 @@
return false;
}
}
-
// Need to load form properties here, because we need to have the children loaded
// Get form properties
Index: src/common/paws/pawstextbox.cpp
===================================================================
--- src/common/paws/pawstextbox.cpp (revision 5445)
+++ src/common/paws/pawstextbox.cpp (working copy)
@@ -59,7 +59,7 @@
}
bool pawsTextBox::Setup( iDocumentNode* node )
-{
+{
csRef vertAttribute = node->GetAttribute("vertical");
if ( vertAttribute )
SetVertical(strcmp(vertAttribute->GetValue(), "yes") == 0);
@@ -386,7 +386,7 @@
void pawsMessageTextBox::Clear()
{
messages.Empty();
- adjusted.Empty();
+ messageLines.Empty();
topLine = 0;
if (scrollBar)
scrollBar->Hide();
@@ -401,66 +401,80 @@
bool pawsMessageTextBox::Setup( iDocumentNode* node )
{
+
csRef scrollBarNode = node->GetNode( "pawsScrollBar" );
if ( scrollBarNode )
{
- CalcLineHeight();
-
- // Create the optional scroll bar here as well but hidden.
- scrollBar = new pawsScrollBar;
- //TODO: FIGURE OUT WHY THIS FUNCTION DOESN'T SETUP SCROLLBARS CORRECTLY!
- //scrollBar->Setup( scrollBarNode );
- scrollBar->SetParent( this );
-
+ BeforeSetup();
csRef widthAttribute = scrollBarNode->GetAttribute("width");
- int scrollBarWidth = 25;
+ int scrollBarWidth = 24;
if(widthAttribute){
scrollBarWidth = widthAttribute->GetValueAsInt();
}
-
scrollBar->SetRelativeFrame( defaultFrame.Width() - scrollBarWidth, 6, scrollBarWidth, defaultFrame.Height() - 12 );
-
- int attach = ATTACH_TOP | ATTACH_BOTTOM | ATTACH_RIGHT;
- scrollBar->SetAttachFlags( attach );
- scrollBar->PostSetup();
- AddChild( scrollBar );
- OnResize();
- return true;
+ AfterSetup();
}
else
{
- return Setup();
+ Setup();
}
+ return true;
}
bool pawsMessageTextBox::Setup()
{
+ BeforeSetup();
+ scrollBar->SetRelativeFrame( defaultFrame.Width() - 24, 6, 24, defaultFrame.Height() - 12 );
+ scrollBar->SetTickValue( 1.0 );
+ scrollBar->SetMaxValue(0.0);
+ scrollBar->PostSetup();
+ AfterSetup();
+ return true;
+}
+
+void pawsMessageTextBox::BeforeSetup()
+{
CalcLineHeight();
// Create the optional scroll bar here as well but hidden.
- scrollBar = new pawsScrollBar;
+ scrollBar = GetScrollBar();
+ scrollBar->SetName("pawsMessageTexBox::ScrollBar");
scrollBar->SetParent( this );
- scrollBar->SetRelativeFrame( defaultFrame.Width() - 24, 6, 24, defaultFrame.Height() - 12 );
- int attach = ATTACH_TOP | ATTACH_BOTTOM | ATTACH_RIGHT;
- scrollBar->SetAttachFlags( attach );
- scrollBar->PostSetup();
- scrollBar->SetTickValue( 1.0 );
- scrollBar->SetMaxValue(0.0);
- AddChild( scrollBar );
+}
+pawsScrollBar* pawsMessageTextBox::GetScrollBar()
+{
+ for ( size_t x = 0; x < children.GetSize(); x++ )
+ {
+ csString widgetName(children[x]->GetName());
+ if (widgetName.Compare("pawsWidget::pawsScrollBar"))
+ {
+ return (pawsScrollBar*)children[x];
+ }
+ }
+
+ return new pawsScrollBar;
+}
+
+
+void pawsMessageTextBox::AfterSetup()
+{
OnResize();
-
- return true;
}
-void pawsMessageTextBox::Resize()
+void pawsMessageTextBox::OnResize()
{
- pawsWidget::Resize();
-
CalcLineHeight();
- adjusted.Empty();
+ ResizeMessage();
+ AdjustScrollBar();
+
+}
+void pawsMessageTextBox::ResizeMessage()
+{
+ messageLines.Empty();
+
for ( size_t x = 0; x < messages.GetSize(); x++ )
{
MessageLine* dummy = NULL;
@@ -474,42 +488,35 @@
for(size_t i = 0; i < messages[x]->segments.GetSize(); i++)
SplitMessage( messages[x]->segments[i].text, messages[x]->segments[i].colour, messages[x]->segments[i].size, msgLine, offsetX);
}
- }
+ }
}
-void pawsMessageTextBox::OnResize()
+void pawsMessageTextBox::AdjustScrollBar()
{
int borderOffSize = 4;
if ( border )
borderOffSize = 8;
- int rest = (screenFrame.Height()-borderOffSize) % lineHeight;
- if (screenFrame.Height() >= borderOffSize+rest)
- maxLines = (screenFrame.Height()-borderOffSize-rest) / lineHeight;
+ if (screenFrame.Height() >= borderOffSize)
+ maxLines = (screenFrame.Height()-borderOffSize) / lineHeight;
else
maxLines = 0;
- // Re adjust the top line value
- topLine = (int)adjusted.GetSize() - (int)maxLines;
- if ( topLine < 0 )
- topLine = 0;
-
if (scrollBar)
{
- scrollBar->SetMaxValue( maxLines > adjusted.GetSize() ? 0 : (float)(adjusted.GetSize()-maxLines) );
- scrollBar->SetCurrentValue( (float)topLine );
-
- if ( maxLines < adjusted.GetSize() )
+ scrollBar->SetMaxValue( maxLines > messageLines.GetSize() ? 0 : (float)(messageLines.GetSize()-maxLines) );
+ if ( maxLines < messageLines.GetSize() )
{
scrollBar->Show();
scrollBar->RecalcScreenPositions();
}
else
+ {
scrollBar->Hide();
+ }
}
}
-
void pawsMessageTextBox::Draw()
{
pawsWidget::Draw();
@@ -523,9 +530,9 @@
for ( size_t x = topLine; x < (topLine+maxLines); x++ )
{
- if ( x < adjusted.GetSize() )
+ if ( x < messageLines.GetSize() )
{
- if(adjusted[x]->segments.IsEmpty())
+ if(messageLines[x]->segments.IsEmpty())
{
// Draw shadow
graphics2D->Write( GetFont(),
@@ -533,33 +540,33 @@
screenFrame.ymin + yPos*lineHeight + 1,
0,
-1,
- (const char*)adjusted[x]->text );
+ (const char*)messageLines[x]->text );
// Draw actual text
graphics2D->Write( GetFont(),
screenFrame.xmin,
screenFrame.ymin + yPos*lineHeight,
- adjusted[x]->colour,
+ messageLines[x]->colour,
-1,
- (const char*)adjusted[x]->text );
+ (const char*)messageLines[x]->text );
}
else
{
- for(size_t i = 0; i < adjusted[x]->segments.GetSize(); i++)
+ for(size_t i = 0; i < messageLines[x]->segments.GetSize(); i++)
{
// Draw shadow
graphics2D->Write( GetFont(),
- screenFrame.xmin + adjusted[x]->segments[i].x + 1,
+ screenFrame.xmin + messageLines[x]->segments[i].x + 1,
screenFrame.ymin + yPos*lineHeight + 1,
0,
-1,
- (const char*)adjusted[x]->segments[i].text );
+ (const char*)messageLines[x]->segments[i].text );
// Draw actual text
graphics2D->Write( GetFont(),
- screenFrame.xmin + adjusted[x]->segments[i].x,
+ screenFrame.xmin + messageLines[x]->segments[i].x,
screenFrame.ymin + yPos*lineHeight,
- adjusted[x]->segments[i].colour,
+ messageLines[x]->segments[i].colour,
-1,
- (const char*)adjusted[x]->segments[i].text );
+ (const char*)messageLines[x]->segments[i].text );
}
}
@@ -715,16 +722,16 @@
messages.Push(msg);
if (scrollBar)
{
- if ( adjusted.GetSize() > maxLines )
+ if ( messageLines.GetSize() > maxLines )
scrollBar->ShowBehind();
else
scrollBar->Hide();
}
- scrollBar->SetMaxValue( maxLines > adjusted.GetSize() ? 0 : (float)(adjusted.GetSize()-maxLines) );
+ scrollBar->SetMaxValue( maxLines > messageLines.GetSize() ? 0 : (float)(messageLines.GetSize()-maxLines) );
- topLine = (int)adjusted.GetSize() - (int)maxLines;
+ topLine = (int)messageLines.GetSize() - (int)maxLines;
if ( topLine < 0 )
topLine = 0;
@@ -751,7 +758,7 @@
MessageLine* line = messages.Get(messages.GetSize()-1);
line->text.Append(data);
- line = adjusted.Get(adjusted.GetSize()-1);
+ line = messageLines.Get(messageLines.GetSize()-1);
line->text.Append(data);
// Trim \n from the end and add a new line.
@@ -852,7 +859,7 @@
msgLine->size = text.Length();
msgLine->text = text;
msgLine->colour = colour;
- adjusted.Push(msgLine);
+ messageLines.Push(msgLine);
}
void pawsMessageTextBox::WriteMessageSegment(MessageLine*& msgLine, csString text, int colour, int startPosition)
@@ -1452,6 +1459,7 @@
{
// Create the optional scroll bar here as well but hidden.
scrollBar = new pawsScrollBar();
+ scrollBar->SetName("pawsMultiLineTextBox::ScrollBar");
scrollBar->SetParent( this );
scrollBar->SetRelativeFrame( defaultFrame.Width() - 40, 6, 24, defaultFrame.Height() - 12 );
scrollBar->SetAttachFlags(ATTACH_TOP | ATTACH_BOTTOM | ATTACH_RIGHT);