some minor changes in controls/image, timings added to listtest

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5865 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-02-06 01:30:21 +00:00
parent 3ccf6cd7ea
commit 81278df2b1
5 changed files with 108 additions and 60 deletions

View File

@@ -632,11 +632,11 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
(void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20)); (void)new wxBitmapButton(panel, -1, bitmap, wxPoint(100, 20));
#if 0 #if 1
// test for masked bitmap display // test for masked bitmap display
bitmap = wxBitmap("test2.bmp", wxBITMAP_TYPE_BMP); bitmap = wxBitmap("test2.bmp", wxBITMAP_TYPE_BMP);
bitmap.SetMask(new wxMask(bitmap, *wxBLUE)); bitmap.SetMask(new wxMask(bitmap, *wxBLUE));
(void)new wxBitmapButton(panel, -1, bitmap, wxPoint(300, 120)); (void)new wxStaticBitmap /* wxBitmapButton */ (panel, -1, bitmap, wxPoint(300, 120));
#endif #endif
wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)), wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)),

View File

@@ -59,7 +59,8 @@ enum ScreenToShow
Show_Text, Show_Text,
Show_Lines, Show_Lines,
Show_Polygons, Show_Polygons,
Show_Mask Show_Mask,
Show_Ops
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -145,6 +146,7 @@ protected:
void DrawTestLines( int x, int y, int width, wxDC &dc ); void DrawTestLines( int x, int y, int width, wxDC &dc );
void DrawText(wxDC& dc); void DrawText(wxDC& dc);
void DrawImages(wxDC& dc); void DrawImages(wxDC& dc);
void DrawWithLogicalOps(wxDC& dc);
void DrawDefault(wxDC& dc); void DrawDefault(wxDC& dc);
private: private:
@@ -172,7 +174,8 @@ enum
File_ShowLines, File_ShowLines,
File_ShowPolygons, File_ShowPolygons,
File_ShowMask, File_ShowMask,
MenuShow_Last = File_ShowMask, File_ShowOps,
MenuShow_Last = File_ShowOps,
MenuOption_First, MenuOption_First,
@@ -556,7 +559,6 @@ void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc )
dash1[0] = 0xFF; dash1[0] = 0xFF;
ud.SetDashes( 1, dash1 ); ud.SetDashes( 1, dash1 );
dc.DrawLine( x+20, y+170, 100, y+170 ); dc.DrawLine( x+20, y+170, 100, y+170 );
} }
void MyCanvas::DrawDefault(wxDC& dc) void MyCanvas::DrawDefault(wxDC& dc)
@@ -583,7 +585,7 @@ void MyCanvas::DrawDefault(wxDC& dc)
memdc.SetPen( *wxWHITE_PEN ); memdc.SetPen( *wxWHITE_PEN );
memdc.DrawRectangle(0,0,20,70); memdc.DrawRectangle(0,0,20,70);
memdc.DrawLine( 10,0,10,70 ); memdc.DrawLine( 10,0,10,70 );
// to the right // to the right
wxPen pen = *wxRED_PEN; wxPen pen = *wxRED_PEN;
pen.SetWidth(2); pen.SetWidth(2);
@@ -592,7 +594,7 @@ void MyCanvas::DrawDefault(wxDC& dc)
memdc.DrawLine( 10,10,11,10 ); memdc.DrawLine( 10,10,11,10 );
memdc.DrawLine( 10,15,12,15 ); memdc.DrawLine( 10,15,12,15 );
memdc.DrawLine( 10,20,13,20 ); memdc.DrawLine( 10,20,13,20 );
/* /*
memdc.SetPen(*wxRED_PEN); memdc.SetPen(*wxRED_PEN);
memdc.DrawLine( 12, 5,12, 5 ); memdc.DrawLine( 12, 5,12, 5 );
@@ -600,7 +602,7 @@ void MyCanvas::DrawDefault(wxDC& dc)
memdc.DrawLine( 12,15,14,15 ); memdc.DrawLine( 12,15,14,15 );
memdc.DrawLine( 12,20,15,20 ); memdc.DrawLine( 12,20,15,20 );
*/ */
// same to the left // same to the left
memdc.DrawLine( 10,25,10,25 ); memdc.DrawLine( 10,25,10,25 );
memdc.DrawLine( 10,30, 9,30 ); memdc.DrawLine( 10,30, 9,30 );
@@ -615,20 +617,19 @@ void MyCanvas::DrawDefault(wxDC& dc)
memdc.DrawLine( 10,55,11,55 ); memdc.DrawLine( 10,55,11,55 );
memdc.DrawLine( 10,60,12,60 ); memdc.DrawLine( 10,60,12,60 );
memdc.DrawLine( 10,65,13,65 ); memdc.DrawLine( 10,65,13,65 );
memdc.DrawLine( 12,50,12,50 ); memdc.DrawLine( 12,50,12,50 );
memdc.DrawLine( 12,55,13,55 ); memdc.DrawLine( 12,55,13,55 );
memdc.DrawLine( 12,60,14,60 ); memdc.DrawLine( 12,60,14,60 );
memdc.DrawLine( 12,65,15,65 ); memdc.DrawLine( 12,65,15,65 );
memdc.SelectObject( wxNullBitmap ); memdc.SelectObject( wxNullBitmap );
dc.DrawBitmap( bitmap, 10, 170 ); dc.DrawBitmap( bitmap, 10, 170 );
wxImage image( bitmap ); wxImage image( bitmap );
image.Rescale( 60,210 ); image.Rescale( 60,210 );
bitmap = image.ConvertToBitmap(); bitmap = image.ConvertToBitmap();
dc.DrawBitmap( bitmap, 50, 170 ); dc.DrawBitmap( bitmap, 50, 170 );
// test the rectangle outline drawing - there should be one pixel between // test the rectangle outline drawing - there should be one pixel between
// the rect and the lines // the rect and the lines
dc.SetPen(*wxWHITE_PEN); dc.SetPen(*wxWHITE_PEN);
@@ -715,31 +716,31 @@ void MyCanvas::DrawText(wxDC& dc)
dc.DrawRectangle( 100, 40, 4, height ); dc.DrawRectangle( 100, 40, 4, height );
} }
static const struct
{
const wxChar *name;
int rop;
} rasterOperations[] =
{
{ "wxAND", wxAND },
{ "wxAND_INVERT", wxAND_INVERT },
{ "wxAND_REVERSE", wxAND_REVERSE },
{ "wxCLEAR", wxCLEAR },
{ "wxCOPY", wxCOPY },
{ "wxEQUIV", wxEQUIV },
{ "wxINVERT", wxINVERT },
{ "wxNAND", wxNAND },
{ "wxNO_OP", wxNO_OP },
{ "wxOR", wxOR },
{ "wxOR_INVERT", wxOR_INVERT },
{ "wxOR_REVERSE", wxOR_REVERSE },
{ "wxSET", wxSET },
{ "wxSRC_INVERT", wxSRC_INVERT },
{ "wxXOR", wxXOR },
};
void MyCanvas::DrawImages(wxDC& dc) void MyCanvas::DrawImages(wxDC& dc)
{ {
static const struct
{
const wxChar *name;
int rop;
} rasterOperations[] =
{
{ "wxAND", wxAND },
{ "wxAND_INVERT", wxAND_INVERT },
{ "wxAND_REVERSE", wxAND_REVERSE },
{ "wxCLEAR", wxCLEAR },
{ "wxCOPY", wxCOPY },
{ "wxEQUIV", wxEQUIV },
{ "wxINVERT", wxINVERT },
{ "wxNAND", wxNAND },
{ "wxNO_OP", wxNO_OP },
{ "wxOR", wxOR },
{ "wxOR_INVERT", wxOR_INVERT },
{ "wxOR_REVERSE", wxOR_REVERSE },
{ "wxSET", wxSET },
{ "wxSRC_INVERT", wxSRC_INVERT },
{ "wxXOR", wxXOR },
};
dc.DrawText("original image", 0, 0); dc.DrawText("original image", 0, 0);
dc.DrawBitmap(gs_bmpNoMask, 0, 20, 0); dc.DrawBitmap(gs_bmpNoMask, 0, 20, 0);
dc.DrawText("with colour mask", 0, 100); dc.DrawText("with colour mask", 0, 100);
@@ -764,6 +765,27 @@ void MyCanvas::DrawImages(wxDC& dc)
} }
} }
void MyCanvas::DrawWithLogicalOps(wxDC& dc)
{
static const wxCoord w = 60;
static const wxCoord h = 60;
// reuse the text colour here
dc.SetPen(wxPen(m_owner->m_colourForeground, 1, wxSOLID));
for ( size_t n = 0; n < WXSIZEOF(rasterOperations); n++ )
{
wxCoord x = 20 + 150*(n%4),
y = 20 + 100*(n/4);
dc.DrawText(rasterOperations[n].name, x, y - 20);
dc.SetLogicalFunction(rasterOperations[n].rop);
//dc.DrawRectangle(x, y, w, h);
dc.DrawLine(x, y, x + w, y + h);
dc.DrawLine(x + w, y, x, y + h);
}
}
void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
{ {
wxPaintDC dc(this); wxPaintDC dc(this);
@@ -804,6 +826,10 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event))
case Show_Mask: case Show_Mask:
DrawImages(dc); DrawImages(dc);
break; break;
case Show_Ops:
DrawWithLogicalOps(dc);
break;
} }
} }
@@ -850,6 +876,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
menuFile->Append(File_ShowLines, "&Lines screen\tF3"); menuFile->Append(File_ShowLines, "&Lines screen\tF3");
menuFile->Append(File_ShowPolygons, "&Polygons screen\tF4"); menuFile->Append(File_ShowPolygons, "&Polygons screen\tF4");
menuFile->Append(File_ShowMask, "wx&Mask screen\tF5"); menuFile->Append(File_ShowMask, "wx&Mask screen\tF5");
menuFile->Append(File_ShowOps, "&ROP screen\tF6");
menuFile->AppendSeparator(); menuFile->AppendSeparator();
menuFile->Append(File_About, "&About...\tCtrl-A", "Show about dialog"); menuFile->Append(File_About, "&About...\tCtrl-A", "Show about dialog");
menuFile->AppendSeparator(); menuFile->AppendSeparator();

View File

@@ -1,2 +1,2 @@
test.png test.png
saved.xpm

View File

@@ -100,9 +100,11 @@ END_EVENT_TABLE()
MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
const wxPoint &pos, const wxSize &size ) const wxPoint &pos, const wxSize &size )
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ), : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
m_bmpSmileXpm((const char **) smile_xpm), #if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
m_iconSmileXpm((const char **) smile_xpm) , m_bmpSmileXpm((const char **) smile_xpm)
, m_iconSmileXpm((const char **) smile_xpm)
#endif
{ {
my_horse_png = (wxBitmap*) NULL; my_horse_png = (wxBitmap*) NULL;
my_horse_jpeg = (wxBitmap*) NULL; my_horse_jpeg = (wxBitmap*) NULL;
@@ -131,7 +133,7 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
// try to find the directory with our images // try to find the directory with our images
wxString dir; wxString dir;
if ( wxFile::Exists("./horse.png") ) if ( wxFile::Exists("./horse.png") )
dir = "./"; dir = "./";
else if ( wxFile::Exists("../horse.png") ) else if ( wxFile::Exists("../horse.png") )
dir = "../"; dir = "../";
else else
@@ -168,6 +170,9 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
wxLogError("Can't load PCX image"); wxLogError("Can't load PCX image");
else else
my_horse_pcx = new wxBitmap( image.ConvertToBitmap() ); my_horse_pcx = new wxBitmap( image.ConvertToBitmap() );
image.LoadFile( dir + wxString("test.pcx") );
my_square = new wxBitmap( image.ConvertToBitmap() );
#endif #endif
if ( !image.LoadFile( dir + wxString("horse.bmp"), wxBITMAP_TYPE_BMP ) ) if ( !image.LoadFile( dir + wxString("horse.bmp"), wxBITMAP_TYPE_BMP ) )
@@ -189,17 +194,16 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id,
my_horse_tiff = new wxBitmap( image.ConvertToBitmap() ); my_horse_tiff = new wxBitmap( image.ConvertToBitmap() );
#endif #endif
image.LoadFile( dir + wxString("test.pcx") );
my_square = new wxBitmap( image.ConvertToBitmap() );
CreateAntiAliasedBitmap(); CreateAntiAliasedBitmap();
my_smile_xbm = new wxBitmap( (const char*)smile_bits, smile_width, my_smile_xbm = new wxBitmap( (const char*)smile_bits, smile_width,
smile_height, 1 ); smile_height, 1 );
#if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW
// demonstrates XPM automatically using the mask when saving // demonstrates XPM automatically using the mask when saving
if ( m_bmpSmileXpm.Ok() ) if ( m_bmpSmileXpm.Ok() )
m_bmpSmileXpm.SaveFile("saved.xpm", wxBITMAP_TYPE_XPM); m_bmpSmileXpm.SaveFile("saved.xpm", wxBITMAP_TYPE_XPM);
#endif
} }
MyCanvas::~MyCanvas() MyCanvas::~MyCanvas()
@@ -398,7 +402,7 @@ MyFrame::MyFrame()
wxPoint(20,20), wxSize(470,360) ) wxPoint(20,20), wxSize(470,360) )
{ {
wxMenu *file_menu = new wxMenu(); wxMenu *file_menu = new wxMenu();
file_menu->Append( ID_ABOUT, "&About.."); file_menu->Append( ID_ABOUT, "&About...");
file_menu->Append( ID_QUIT, "E&xit"); file_menu->Append( ID_QUIT, "E&xit");
wxMenuBar *menu_bar = new wxMenuBar(); wxMenuBar *menu_bar = new wxMenuBar();

View File

@@ -30,6 +30,7 @@
#endif #endif
#include "wx/listctrl.h" #include "wx/listctrl.h"
#include "wx/timer.h" // for wxStopWatch
#include "listtest.h" #include "listtest.h"
BEGIN_EVENT_TABLE(MyFrame, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
@@ -132,12 +133,12 @@ bool MyApp::OnInit(void)
// Make a menubar // Make a menubar
wxMenu *file_menu = new wxMenu; wxMenu *file_menu = new wxMenu;
file_menu->Append(LIST_LIST_VIEW, "&List view"); file_menu->Append(LIST_LIST_VIEW, "&List view\tF1");
file_menu->Append(LIST_REPORT_VIEW, "&Report view"); file_menu->Append(LIST_REPORT_VIEW, "&Report view\tF2");
file_menu->Append(LIST_ICON_VIEW, "&Icon view"); file_menu->Append(LIST_ICON_VIEW, "&Icon view\tF3");
file_menu->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text"); file_menu->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text\tF4");
file_menu->Append(LIST_SMALL_ICON_VIEW, "&Small icon view"); file_menu->Append(LIST_SMALL_ICON_VIEW, "&Small icon view\tF5");
file_menu->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text"); file_menu->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text\tF6");
file_menu->Append(LIST_DESELECT_ALL, "&Deselect All"); file_menu->Append(LIST_DESELECT_ALL, "&Deselect All");
file_menu->Append(LIST_SELECT_ALL, "S&elect All"); file_menu->Append(LIST_SELECT_ALL, "S&elect All");
file_menu->AppendSeparator(); file_menu->AppendSeparator();
@@ -149,7 +150,7 @@ bool MyApp::OnInit(void)
file_menu->Append(BUSY_OFF, "&Busy cursor off"); file_menu->Append(BUSY_OFF, "&Busy cursor off");
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(LIST_ABOUT, "&About"); file_menu->Append(LIST_ABOUT, "&About");
file_menu->Append(LIST_QUIT, "E&xit"); file_menu->Append(LIST_QUIT, "E&xit\tAlt-X");
wxMenuBar *menu_bar = new wxMenuBar; wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, "&File"); menu_bar->Append(file_menu, "&File");
frame->SetMenuBar(menu_bar); frame->SetMenuBar(menu_bar);
@@ -274,20 +275,30 @@ void MyFrame::OnReportView(wxCommandEvent& WXUNUSED(event))
m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140); m_listCtrl->InsertColumn(1, "Column 2"); // , wxLIST_FORMAT_LEFT, 140);
m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140); m_listCtrl->InsertColumn(2, "One More Column (2)"); // , wxLIST_FORMAT_LEFT, 140);
for ( int i = 0; i < 300; i++ ) // to speed up inserting we hide the control temporarily
m_listCtrl->Hide();
wxStopWatch sw;
wxString buf;
static const int NUM_ITEMS = 3000;
for ( int i = 0; i < NUM_ITEMS; i++ )
{ {
wxChar buf[50]; buf.Printf(_T("This is item %d"), i);
wxSprintf(buf, _T("This is item %d"), i);
long tmp = m_listCtrl->InsertItem(i, buf, 0); long tmp = m_listCtrl->InsertItem(i, buf, 0);
m_listCtrl->SetItemData(tmp, i); m_listCtrl->SetItemData(tmp, i);
wxSprintf(buf, _T("Col 1, item %d"), i); buf.Printf(_T("Col 1, item %d"), i);
tmp = m_listCtrl->SetItem(i, 1, buf); tmp = m_listCtrl->SetItem(i, 1, buf);
wxSprintf(buf, _T("Item %d in column 2"), i); buf.Printf(_T("Item %d in column 2"), i);
tmp = m_listCtrl->SetItem(i, 2, buf); tmp = m_listCtrl->SetItem(i, 2, buf);
} }
m_logWindow->WriteText(wxString::Format(_T("%d items inserted in %ldms\n"),
NUM_ITEMS, sw.Time()));
m_listCtrl->Show();
// we leave all mask fields to 0 and only change the colour // we leave all mask fields to 0 and only change the colour
wxListItem item; wxListItem item;
item.m_itemId = 0; item.m_itemId = 0;
@@ -371,18 +382,24 @@ void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event))
{ {
wxStopWatch sw;
m_listCtrl->SortItems(MyCompareFunction, 0); m_listCtrl->SortItems(MyCompareFunction, 0);
m_logWindow->WriteText(wxString::Format(_T("Sorting %d items took %ld ms\n"),
m_listCtrl->GetItemCount(),
sw.Time()));
} }
void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnDeleteAll(wxCommandEvent& WXUNUSED(event))
{ {
(void)wxGetElapsedTime(TRUE); wxStopWatch sw;
int nItems = m_listCtrl->GetItemCount();
m_listCtrl->DeleteAllItems(); m_listCtrl->DeleteAllItems();
wxLogMessage("Deleting %d items took %ld ms", m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"),
nItems, wxGetElapsedTime()); m_listCtrl->GetItemCount(),
sw.Time()));
} }
// MyListCtrl // MyListCtrl