(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)),
Show_Text,
Show_Lines,
Show_Polygons,
- Show_Mask
+ Show_Mask,
+ Show_Ops
};
// ----------------------------------------------------------------------------
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:
File_ShowLines,
File_ShowPolygons,
File_ShowMask,
- MenuShow_Last = File_ShowMask,
+ File_ShowOps,
+ MenuShow_Last = File_ShowOps,
MenuOption_First,
dash1[0] = 0xFF;
ud.SetDashes( 1, dash1 );
dc.DrawLine( x+20, y+170, 100, y+170 );
-
}
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);
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 );
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 );
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);
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);
}
}
+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);
case Show_Mask:
DrawImages(dc);
break;
+
+ case Show_Ops:
+ DrawWithLogicalOps(dc);
+ break;
}
}
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();
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;
// 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
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 ) )
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()
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();
#endif
#include "wx/listctrl.h"
+#include "wx/timer.h" // for wxStopWatch
#include "listtest.h"
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
// 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();
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);
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;
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