All pastes #1776973 Raw Edit

clueless

public text v1 · immutable
#1776973 ·published 2010-02-03 13:05 UTC
rendered paste body
Index: src/common/paws/pawstextbox.h===================================================================--- src/common/paws/pawstextbox.h	(revision 5421)+++ 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<MessageLine> adjusted;+    csPDelArray<MessageLine> 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 5421)+++ src/common/paws/pawscrollbar.cpp	(working copy)@@ -132,7 +132,7 @@     attr = node->GetAttribute("tick");     if (attr)         tickValue = attr->GetValueAsFloat();-+         	// up button settings 	csRef<iDocumentNode> upNode = node->GetNode("up"); 	if (upNode)@@ -168,7 +168,7 @@  	// down button settings 	csRef<iDocumentNode> downNode = node->GetNode("down");-	if (upNode)+	if (downNode) 	{ 		attr = downNode->GetAttribute("grey"); 		if (attr)@@ -265,6 +265,7 @@ {     // Create the scroll up/left button     upButton = new pawsButton;+    upButton->SetName("pawscrollbar::pawsButton::up");     upButton->SetParent( this );     int flags;     if (!horizontal)@@ -301,6 +302,7 @@      // Create the scroll down button.     downButton = new pawsButton;+    downButton->SetName("pawscrollbar::pawsButton::down");     downButton->SetParent( this );     if (!horizontal)     {Index: src/common/paws/pawswidget.cpp===================================================================--- src/common/paws/pawswidget.cpp	(revision 5421)+++ 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 propertiesIndex: src/common/paws/pawstextbox.cpp===================================================================--- src/common/paws/pawstextbox.cpp	(revision 5421)+++ src/common/paws/pawstextbox.cpp	(working copy)@@ -59,7 +59,7 @@ }  bool pawsTextBox::Setup( iDocumentNode* node )-{    +{     csRef<iDocumentAttribute> 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();@@ -404,63 +404,81 @@     csRef<iDocumentNode> 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<iDocumentAttribute> 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);+    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 ); +}++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()+{     int attach = ATTACH_TOP | ATTACH_BOTTOM | ATTACH_RIGHT;     scrollBar->SetAttachFlags( attach );     scrollBar->PostSetup();-    scrollBar->SetTickValue( 1.0 );-    scrollBar->SetMaxValue(0.0);-    AddChild( scrollBar );+//    AddChild( scrollBar );      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 +492,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 +534,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 +544,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 +726,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 +762,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 +863,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 +1463,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);