From: <ma...@us...> - 2003-11-23 15:53:21
|
Update of /cvsroot/sharedaemon/ui-wx/src In directory sc8-pr-cvs1:/tmp/cvs-serv27124 Modified Files: Images.cpp Images.h MainDlg.cpp Log Message: Toolbar images are now generated during runtime and texts added as necessery. This fixes wxMac and wxX11 toolbar and improves visual quality of the whole interface. Index: Images.cpp =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- Images.cpp 21 Nov 2003 11:01:31 -0000 1.15 +++ Images.cpp 23 Nov 2003 15:53:17 -0000 1.16 @@ -120,3 +120,104 @@ leftarrow.LoadFile(path+wxT("leftarrow.png"), wxBITMAP_TYPE_PNG); rightarrow.LoadFile(path+wxT("rightarrow.png"), wxBITMAP_TYPE_PNG); } + +/** + * Here we generate new toolbar button images. First we find out which of + * our texts is longest, and make the bitmap size according to that. Then + * we draw each bitmap with corresponding image and text and save to the + * corresponding image object (note that we should never save it to disc!). + * The main reason for this was wxMac where toolbar button texts were not + * supported, but eventually, this approach proves nicer quality because of + * added background colour and surrounding border to button images. + */ +void CImages::MakeToolImages() { + wxBitmap tmp, tmp_new; + wxMemoryDC mdc; + wxCoord x, y, width = 0; + wxArrayString btntxt; + + /* List of button names */ + btntxt.Add(_("Connect")); + btntxt.Add(_("Servers")); + btntxt.Add(_("Search")); + btntxt.Add(_("Transfer")); + btntxt.Add(_("Shared Files")); + btntxt.Add(_("Messaging")); + btntxt.Add(_("Statistics")); + btntxt.Add(_("Preferences")); + + /* Temporary bitmap for measuring text lengths. 100 pixels should be enuff. */ + tmp = wxBitmap(100, 100); + mdc.SelectObject(tmp); + for (uint i=0;i<btntxt.GetCount();i++) { + mdc.GetTextExtent(btntxt.Item(i), &x, &y); + if (x > width) { + width = x; + } + } + + tmp_new = wxBitmap(width+6, y+36); + mdc.SelectObject(tmp_new); + mdc.DrawRectangle(0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()); + mdc.DrawBitmap(btn_connect, (tmp_new.GetWidth()-32)/2, 2, true); + mdc.GetTextExtent(btntxt.Item(0), &x, &y); + mdc.DrawText(btntxt.Item(0), (tmp_new.GetWidth()-x)/2, 34); + btn_connect = tmp_new; + + tmp_new = wxBitmap(width+6, y+36); + mdc.SelectObject(tmp_new); + mdc.DrawRectangle(0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()); + mdc.DrawBitmap(btn_servers, (tmp_new.GetWidth()-32)/2, 2, true); + mdc.GetTextExtent(btntxt.Item(1), &x, &y); + mdc.DrawText(btntxt.Item(1), (tmp_new.GetWidth()-x)/2, 34); + btn_servers = tmp_new; + + tmp_new = wxBitmap(width+6, y+36); + mdc.SelectObject(tmp_new); + mdc.DrawRectangle(0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()); + mdc.DrawBitmap(btn_search, (tmp_new.GetWidth()-32)/2, 2, true); + mdc.GetTextExtent(btntxt.Item(2), &x, &y); + mdc.DrawText(btntxt.Item(2), (tmp_new.GetWidth()-x)/2, 34); + btn_search = tmp_new; + + tmp_new = wxBitmap(width+6, y+36); + mdc.SelectObject(tmp_new); + mdc.DrawRectangle(0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()); + mdc.DrawBitmap(btn_transfer, (tmp_new.GetWidth()-32)/2, 2, true); + mdc.GetTextExtent(btntxt.Item(3), &x, &y); + mdc.DrawText(btntxt.Item(3), (tmp_new.GetWidth()-x)/2, 34); + btn_transfer = tmp_new; + + tmp_new = wxBitmap(width+6, y+36); + mdc.SelectObject(tmp_new); + mdc.DrawRectangle(0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()); + mdc.DrawBitmap(btn_shared, (tmp_new.GetWidth()-32)/2, 2, true); + mdc.GetTextExtent(btntxt.Item(4), &x, &y); + mdc.DrawText(btntxt.Item(4), (tmp_new.GetWidth()-x)/2, 34); + btn_shared = tmp_new; + + tmp_new = wxBitmap(width+6, y+36); + mdc.SelectObject(tmp_new); + mdc.DrawRectangle(0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()); + mdc.DrawBitmap(btn_messages, (tmp_new.GetWidth()-32)/2, 2, true); + mdc.GetTextExtent(btntxt.Item(5), &x, &y); + mdc.DrawText(btntxt.Item(5), (tmp_new.GetWidth()-x)/2, 34); + btn_messages = tmp_new; + + tmp_new = wxBitmap(width+6, y+36); + mdc.SelectObject(tmp_new); + mdc.DrawRectangle(0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()); + mdc.DrawBitmap(btn_statistics, (tmp_new.GetWidth()-32)/2, 2, true); + mdc.GetTextExtent(btntxt.Item(6), &x, &y); + mdc.DrawText(btntxt.Item(6), (tmp_new.GetWidth()-x)/2, 34); + btn_statistics = tmp_new; + + tmp_new = wxBitmap(width+6, y+36); + mdc.SelectObject(tmp_new); + mdc.DrawRectangle(0, 0, tmp_new.GetWidth(), tmp_new.GetHeight()); + mdc.DrawBitmap(btn_guisettings, (tmp_new.GetWidth()-32)/2, 2, true); + mdc.GetTextExtent(btntxt.Item(7), &x, &y); + mdc.DrawText(btntxt.Item(7), (tmp_new.GetWidth()-x)/2, 34); + btn_guisettings = tmp_new; + +} Index: Images.h =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/Images.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- Images.h 21 Nov 2003 10:26:50 -0000 1.11 +++ Images.h 23 Nov 2003 15:53:17 -0000 1.12 @@ -36,19 +36,13 @@ CImages(); wxBitmap frienduser, messages, search, provider, servers, newserver, updateserver, info, serverinfo, log, files, updown11, updown00, - connected, - disconnected, - timer, - user, - server, - arrow, - stats, + connected, disconnected, timer, user, server, arrow, stats, upload, download, part, full, exclamation, connection, daily, monthly, yearly, mule, btn_connect, btn_servers, btn_transfer, btn_search, btn_shared, btn_messages, btn_statistics, btn_guisettings, btn_preferences, logo, leftarrow, rightarrow; - + void MakeToolImages(); private: void LoadImages(); }; Index: MainDlg.cpp =================================================================== RCS file: /cvsroot/sharedaemon/ui-wx/src/MainDlg.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- MainDlg.cpp 23 Nov 2003 12:14:53 -0000 1.6 +++ MainDlg.cpp 23 Nov 2003 15:53:17 -0000 1.7 @@ -104,6 +104,9 @@ /* Load dialog pages */ LoadAndShowDialogPages(); + /* Generate images for toolbar */ + img->MakeToolImages(); + /** * Toolbar and Menubar must be created AFTER loading dialog pages, * since they do calls to GetCurPage() which results in crash @@ -227,10 +230,10 @@ /* Construct the toolbar object */ wxToolBar *tb = new wxToolBar( this, -1, wxDefaultPosition, wxDefaultSize, - tool_align|wxNO_BORDER|wxTB_TEXT|wxTB_FLAT|wxTB_3DBUTTONS + tool_align|wxNO_BORDER|wxTB_3DBUTTONS ); - tb->SetToolBitmapSize(wxSize(32, 32)); + tb->SetToolBitmapSize(wxSize(40, 40)); tb->SetMargins(2, 2); /* Add the buttons */ @@ -271,6 +274,7 @@ /* And go live */ tb->Realize(); SetToolBar(tb); + tb->Refresh(); /** * Last, but not least, we tell the toolbar which button should |