From: Andrew C. <ac...@us...> - 2003-07-03 00:17:34
|
Update of /cvsroot/planeshift/planeshift/src/client/paws In directory sc8-pr-cvs1:/tmp/cvs-serv5119/src/client/paws Modified Files: pawslistbox.cpp pawslistbox.h Log Message: Some updates to the listbox widget in order to make it more useful Index: pawslistbox.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/paws/pawslistbox.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pawslistbox.cpp 9 Jun 2003 21:55:43 -0000 1.1 --- pawslistbox.cpp 3 Jul 2003 00:17:31 -0000 1.2 *************** *** 22,25 **** --- 22,27 ---- #include "pspawsmanager.h" #include "pawstextbox.h" + #include "pawscrollbar.h" + ////////////////////////////////////////////////////////////////////// *************** *** 29,35 **** :pawsWidget( manager ) { ! columnDef = 0; totalColumns = 0; ! totalRows = 0; } --- 31,41 ---- :pawsWidget( manager ) { ! columnDef = 0; totalColumns = 0; ! totalRows = 0; ! selected = -1; ! topRow = 0; ! ! scrollBar = 0; } *************** *** 42,70 **** void pawsListBox::Clear() { ! while ( children.Length() > 0 ) ! { ! delete children[0]; ! children.Delete(0); ! } ! ! totalRows = 0; ! ! UseBorder(); ! ! pawsListBoxRow* box = NewRow(); ! box->SetName("ListTitleBar"); ! ! for ( int col = 0; col < totalColumns; col++ ) { ! pawsTextBox *text = (pawsTextBox*)box->GetColumn(col); ! text->SetText( columnDef[col].name ); ! text->SetFont(); ! text->SetColour(); ! text->Adjust( pawsTextBox::CENTRE ); } ! rows.DeleteAll(); } bool pawsListBox::Setup( iDocumentNode* node ) { --- 48,62 ---- void pawsListBox::Clear() { ! for ( int x = 0; x < rows.Length(); x++ ) { ! children.Delete( rows[x] ); ! delete rows[x]; } ! totalRows = 0; ! if ( scrollBar ) scrollBar->Hide(); } + bool pawsListBox::Setup( iDocumentNode* node ) { *************** *** 90,107 **** } ! pawsListBoxRow* box = NewRow(); ! box->SetName("ListTitleBar"); ! for ( int col = 0; col < totalColumns; col++ ) { ! pawsTextBox *text = (pawsTextBox*)box->GetColumn(col); ! text->SetText( columnDef[col].name ); ! text->SetFont(); ! text->SetColour(); ! text->Adjust( pawsTextBox::CENTRE ); } ! return true; } pawsListBoxRow* pawsListBox::NewRow( int position ) { --- 82,125 ---- } ! CreateTitleRow(); ! ! return true; ! } ! ! bool pawsListBox::PostSetup() ! { ! scrollBar = ( pawsScrollBar* ) windowManager->CreateWidget( "pawsScrollBar" ); ! scrollBar->SetParent( this ); ! scrollBar->SetRelativeFrame( defaultFrame.Width() - 36, 6, ! 24, defaultFrame.Height() - 12 ); ! ! int attach = ATTACH_TOP | ATTACH_BOTTOM | ATTACH_RIGHT; ! scrollBar->SetAttachFlags( attach ); ! scrollBar->UseBorder(); ! scrollBar->PostSetup(); ! scrollBar->SetTickValue( 1.0 ); ! AddChild( scrollBar ); ! ! return true; ! } ! ! void pawsListBox::CreateTitleRow() ! { ! pawsListBoxRow* newRow = new pawsListBoxRow( windowManager ); ! newRow->SetParent( this ); ! ! newRow->SetRelativeFrame( 5, 5, ! ScreenFrame().Width() - 5, ScreenFrame().Height() -5 ); ! ! for ( int x = 0; x < totalColumns; x++ ) { ! newRow->AddTitleColumn( x, columnDef ); } ! ! AddChild( newRow ); } + pawsListBoxRow* pawsListBox::NewRow( int position ) { *************** *** 110,114 **** newRow->SetParent( this ); ! newRow->SetRelativeFrame( 5,totalRows*columnHeight+5, ScreenFrame().Width()-5, columnHeight-5 ); for ( int x = 0; x < totalColumns; x++ ) --- 128,132 ---- newRow->SetParent( this ); ! newRow->SetRelativeFrame( 5,(totalRows+1)*columnHeight+5, ScreenFrame().Width()-5, columnHeight-5 ); for ( int x = 0; x < totalColumns; x++ ) *************** *** 127,130 **** --- 145,155 ---- totalRows++; + if ( scrollBar ) + { + scrollBar->SetMaxValue( (float)totalRows ); + scrollBar->SetCurrentValue( (float)topRow ); + } + + CalculateDrawPositions(); newRow->SetBackground("Standard Background"); *************** *** 137,150 **** bool pawsListBox::Select( pawsListBoxRow* row ) { for ( int x = 0; x < rows.Length(); x++ ) { if ( rows[x] == row ) ! rows[x]->SetBackgroundAlpha(0); else rows[x]->SetBackgroundAlpha(255); } return true; } //-------------------------------------------------------------------------- --- 162,242 ---- bool pawsListBox::Select( pawsListBoxRow* row ) { + selected = -1; + for ( int x = 0; x < rows.Length(); x++ ) { if ( rows[x] == row ) ! { ! selected = x; ! rows[x]->SetBackgroundAlpha(0); ! } else rows[x]->SetBackgroundAlpha(255); } + + if ( selected == -1 ) + return false; + + parent->Selected( this ); + + return true; + } + + void pawsListBox::CalculateDrawPositions() + { + // -1 because of title row. + int numberOfRows = screenFrame.Height() / columnDef[0].height - 1; + + if ( rows.Length() > numberOfRows ) + { + if ( scrollBar ) scrollBar->Show(); + } + + //Hide all rows to start with then figure out which ones to draw. + for ( int x = 0; x < rows.Length(); x++ ) + rows[x]->Hide(); + + int row = topRow; + for ( int z = 0; z < numberOfRows; z++ ) + { + if ( row < rows.Length() ) + { + // +1 because of title row. + int positionY = ( (z+1) * columnDef[0].height + 5 ); + + rows[row]->Show(); + rows[row]->MoveTo( ScreenFrame().xmin + 5, ScreenFrame().ymin + positionY ); + row++; + } + else + break; + } + } + + bool pawsListBox::OnScroll( int direction, pawsScrollBar* widget ) + { + topRow = (int) widget->GetCurrentValue(); + CalculateDrawPositions(); + return true; } + pawsListBoxRow* pawsListBox::GetSelectedRow() + { + if ( selected == -1 ) return 0; + return GetRow( selected ); + } + + + pawsListBoxRow* pawsListBox::GetRow( int x ) + { + if ( x >= 0 && x < rows.Length() ) + return rows[x]; + else + return 0; + } + + + //-------------------------------------------------------------------------- *************** *** 164,171 **** pawsWidget* pawsListBoxRow::GetColumn( int column ) { ! if ( border ) ! return children[column+1]; ! else ! return children[column]; } --- 256,260 ---- pawsWidget* pawsListBoxRow::GetColumn( int column ) { ! return columns[column]; } *************** *** 187,191 **** --- 276,305 ---- } + columns.Push( widget ); AddChild( widget ); } + void pawsListBoxRow::AddTitleColumn( int column, ColumnDef* def ) + { + pawsWidget* widget = windowManager->CreateWidget("pawsTextBox"); + widget->SetParent( this ); + widget->SetName( def[column].name ); + + pawsTextBox* text = (pawsTextBox*)widget; + text->SetText( def[column].name ); + + if ( column == 0 ) + { + widget->SetRelativeFrame( 4,4, def[column].width, def[column].height ); + } + else + { + int offset = 0; + for ( int x = 0; x < column; x++ ) offset+=def[x].width; + + widget->SetRelativeFrame( offset+4, 4, def[column].width, def[column].height ); + } + + + AddChild( widget ); + } Index: pawslistbox.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/client/paws/pawslistbox.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pawslistbox.h 9 Jun 2003 21:55:43 -0000 1.1 --- pawslistbox.h 3 Jul 2003 00:17:31 -0000 1.2 *************** *** 26,29 **** --- 26,31 ---- #include "util/log.h" + class pawsScrollBar; + /** Defines the structure of the list box table. */ *************** *** 41,52 **** class pawsListBoxRow : public pawsWidget { ! public: ! pawsListBoxRow( psPawsManager* manager ); ! bool OnMouseDown(int button, int x, int y ); ! pawsWidget* GetColumn( int column ); ! void AddColumn( int column, ColumnDef* def ); ! private: }; --- 43,60 ---- class pawsListBoxRow : public pawsWidget { ! public: ! pawsListBoxRow( psPawsManager* manager ); ! bool OnMouseDown(int button, int x, int y ); ! pawsWidget* GetColumn( int column ); ! void AddColumn( int column, ColumnDef* def ); ! /** Creates a special row that is the title. ! */ ! void AddTitleColumn( int column, ColumnDef* def ); ! ! private: ! csPArray<pawsWidget> columns; ! }; *************** *** 59,64 **** --- 67,80 ---- pawsListBox( psPawsManager* manager ); bool Setup( iDocumentNode* node ); + bool PostSetup(); + virtual ~pawsListBox(); + /** Get the row that is currently selected. + * @return A pointer to the selected row or NULL. + */ + pawsListBoxRow* GetSelectedRow(); + + pawsListBoxRow* GetRow( int x ); pawsListBoxRow* NewRow( int position = -1 ); *************** *** 66,73 **** --- 82,99 ---- void Clear(); bool Select( pawsListBoxRow* row ); + + void CreateTitleRow(); + bool OnScroll( int direction, pawsScrollBar* widget ); + protected: + void CalculateDrawPositions(); + + pawsScrollBar* scrollBar; + int totalColumns; int totalRows; int columnHeight; + int topRow; + int selected; ColumnDef *columnDef; |