From 81278df2b1e34028bfaf80ba5b61c505dc67d53b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 6 Feb 2000 01:30:21 +0000 Subject: [PATCH] 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 --- samples/controls/controls.cpp | 4 +- samples/drawing/drawing.cpp | 93 ++++++++++++++++++++++------------- samples/image/.cvsignore | 2 +- samples/image/image.cpp | 20 +++++--- samples/listctrl/listtest.cpp | 49 ++++++++++++------ 5 files changed, 108 insertions(+), 60 deletions(-) diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index f2c5c1165c..922b59d2e6 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -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)); -#if 0 +#if 1 // test for masked bitmap display bitmap = wxBitmap("test2.bmp", wxBITMAP_TYPE_BMP); 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 wxBitmap bmp1(wxTheApp->GetStdIcon(wxICON_INFORMATION)), diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index 8bde375feb..3f7ba1f9ff 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -59,7 +59,8 @@ enum ScreenToShow Show_Text, Show_Lines, Show_Polygons, - Show_Mask + Show_Mask, + Show_Ops }; // ---------------------------------------------------------------------------- @@ -145,6 +146,7 @@ protected: void DrawTestLines( int x, int y, int width, wxDC &dc ); void DrawText(wxDC& dc); void DrawImages(wxDC& dc); + void DrawWithLogicalOps(wxDC& dc); void DrawDefault(wxDC& dc); private: @@ -172,7 +174,8 @@ enum File_ShowLines, File_ShowPolygons, File_ShowMask, - MenuShow_Last = File_ShowMask, + File_ShowOps, + MenuShow_Last = File_ShowOps, MenuOption_First, @@ -556,7 +559,6 @@ void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc ) dash1[0] = 0xFF; ud.SetDashes( 1, dash1 ); dc.DrawLine( x+20, y+170, 100, y+170 ); - } void MyCanvas::DrawDefault(wxDC& dc) @@ -583,7 +585,7 @@ void MyCanvas::DrawDefault(wxDC& dc) memdc.SetPen( *wxWHITE_PEN ); memdc.DrawRectangle(0,0,20,70); memdc.DrawLine( 10,0,10,70 ); - + // to the right wxPen pen = *wxRED_PEN; pen.SetWidth(2); @@ -592,7 +594,7 @@ void MyCanvas::DrawDefault(wxDC& dc) memdc.DrawLine( 10,10,11,10 ); memdc.DrawLine( 10,15,12,15 ); memdc.DrawLine( 10,20,13,20 ); - + /* memdc.SetPen(*wxRED_PEN); memdc.DrawLine( 12, 5,12, 5 ); @@ -600,7 +602,7 @@ void MyCanvas::DrawDefault(wxDC& dc) memdc.DrawLine( 12,15,14,15 ); memdc.DrawLine( 12,20,15,20 ); */ - + // same to the left memdc.DrawLine( 10,25,10,25 ); memdc.DrawLine( 10,30, 9,30 ); @@ -615,20 +617,19 @@ void MyCanvas::DrawDefault(wxDC& dc) memdc.DrawLine( 10,55,11,55 ); memdc.DrawLine( 10,60,12,60 ); memdc.DrawLine( 10,65,13,65 ); - + memdc.DrawLine( 12,50,12,50 ); memdc.DrawLine( 12,55,13,55 ); memdc.DrawLine( 12,60,14,60 ); memdc.DrawLine( 12,65,15,65 ); - + memdc.SelectObject( wxNullBitmap ); dc.DrawBitmap( bitmap, 10, 170 ); wxImage image( bitmap ); image.Rescale( 60,210 ); bitmap = image.ConvertToBitmap(); dc.DrawBitmap( bitmap, 50, 170 ); - - + // test the rectangle outline drawing - there should be one pixel between // the rect and the lines dc.SetPen(*wxWHITE_PEN); @@ -715,31 +716,31 @@ void MyCanvas::DrawText(wxDC& dc) dc.DrawRectangle( 100, 40, 4, height ); } -void MyCanvas::DrawImages(wxDC& dc) +static const struct { - 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 }, - }; + 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) +{ dc.DrawText("original image", 0, 0); dc.DrawBitmap(gs_bmpNoMask, 0, 20, 0); 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)) { wxPaintDC dc(this); @@ -804,6 +826,10 @@ void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) case Show_Mask: DrawImages(dc); 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_ShowPolygons, "&Polygons screen\tF4"); menuFile->Append(File_ShowMask, "wx&Mask screen\tF5"); + menuFile->Append(File_ShowOps, "&ROP screen\tF6"); menuFile->AppendSeparator(); menuFile->Append(File_About, "&About...\tCtrl-A", "Show about dialog"); menuFile->AppendSeparator(); diff --git a/samples/image/.cvsignore b/samples/image/.cvsignore index f7a0c2541b..490fbafc25 100644 --- a/samples/image/.cvsignore +++ b/samples/image/.cvsignore @@ -1,2 +1,2 @@ test.png - +saved.xpm diff --git a/samples/image/image.cpp b/samples/image/image.cpp index b55dcc9eb1..63cc8f3b17 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -100,9 +100,11 @@ END_EVENT_TABLE() MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size ) - : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ), - m_bmpSmileXpm((const char **) smile_xpm), - m_iconSmileXpm((const char **) smile_xpm) + : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ) +#if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW + , m_bmpSmileXpm((const char **) smile_xpm) + , m_iconSmileXpm((const char **) smile_xpm) +#endif { my_horse_png = (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 wxString dir; if ( wxFile::Exists("./horse.png") ) - dir = "./"; + dir = "./"; else if ( wxFile::Exists("../horse.png") ) dir = "../"; else @@ -168,6 +170,9 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, wxLogError("Can't load PCX image"); else my_horse_pcx = new wxBitmap( image.ConvertToBitmap() ); + + image.LoadFile( dir + wxString("test.pcx") ); + my_square = new wxBitmap( image.ConvertToBitmap() ); #endif 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() ); #endif - image.LoadFile( dir + wxString("test.pcx") ); - my_square = new wxBitmap( image.ConvertToBitmap() ); - CreateAntiAliasedBitmap(); my_smile_xbm = new wxBitmap( (const char*)smile_bits, smile_width, smile_height, 1 ); +#if !defined(__WINDOWS__) || wxUSE_XPM_IN_MSW // demonstrates XPM automatically using the mask when saving if ( m_bmpSmileXpm.Ok() ) m_bmpSmileXpm.SaveFile("saved.xpm", wxBITMAP_TYPE_XPM); +#endif } MyCanvas::~MyCanvas() @@ -398,7 +402,7 @@ MyFrame::MyFrame() wxPoint(20,20), wxSize(470,360) ) { wxMenu *file_menu = new wxMenu(); - file_menu->Append( ID_ABOUT, "&About.."); + file_menu->Append( ID_ABOUT, "&About..."); file_menu->Append( ID_QUIT, "E&xit"); wxMenuBar *menu_bar = new wxMenuBar(); diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index 8c4e700899..7d3fc9010c 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -30,6 +30,7 @@ #endif #include "wx/listctrl.h" +#include "wx/timer.h" // for wxStopWatch #include "listtest.h" BEGIN_EVENT_TABLE(MyFrame, wxFrame) @@ -132,12 +133,12 @@ bool MyApp::OnInit(void) // Make a menubar wxMenu *file_menu = new wxMenu; - file_menu->Append(LIST_LIST_VIEW, "&List view"); - file_menu->Append(LIST_REPORT_VIEW, "&Report view"); - file_menu->Append(LIST_ICON_VIEW, "&Icon view"); - file_menu->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text"); - file_menu->Append(LIST_SMALL_ICON_VIEW, "&Small icon view"); - file_menu->Append(LIST_SMALL_ICON_TEXT_VIEW, "Small icon &view with text"); + file_menu->Append(LIST_LIST_VIEW, "&List view\tF1"); + file_menu->Append(LIST_REPORT_VIEW, "&Report view\tF2"); + file_menu->Append(LIST_ICON_VIEW, "&Icon view\tF3"); + file_menu->Append(LIST_ICON_TEXT_VIEW, "Icon view with &text\tF4"); + file_menu->Append(LIST_SMALL_ICON_VIEW, "&Small icon view\tF5"); + 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_SELECT_ALL, "S&elect All"); file_menu->AppendSeparator(); @@ -149,7 +150,7 @@ bool MyApp::OnInit(void) file_menu->Append(BUSY_OFF, "&Busy cursor off"); file_menu->AppendSeparator(); 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; menu_bar->Append(file_menu, "&File"); 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(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]; - wxSprintf(buf, _T("This is item %d"), i); + buf.Printf(_T("This is item %d"), i); long tmp = m_listCtrl->InsertItem(i, buf, 0); 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); - 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); } + 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 wxListItem item; item.m_itemId = 0; @@ -371,18 +382,24 @@ void MyFrame::OnSmallIconTextView(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSort(wxCommandEvent& WXUNUSED(event)) { + wxStopWatch sw; + 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)wxGetElapsedTime(TRUE); + wxStopWatch sw; - int nItems = m_listCtrl->GetItemCount(); m_listCtrl->DeleteAllItems(); - wxLogMessage("Deleting %d items took %ld ms", - nItems, wxGetElapsedTime()); + m_logWindow->WriteText(wxString::Format(_T("Deleting %d items took %ld ms\n"), + m_listCtrl->GetItemCount(), + sw.Time())); } // MyListCtrl -- 2.45.2