Customizing Art in wxWidgets

team bbl


wxArtProvider is a class that allows you to customize the built-in graphics ("art") in a wxWidgets application. For example, you might want to replace the standard icons used by the wxWidgets HTML Help viewer or the icons used by the generic dialogs such as the log dialog.

wxWidgets provides a standard wxArtProvider object, and parts of the framework that need icons and bitmaps call wxArtProvider::GetBitmap and wxArtProvider::GetIcon to retrieve a graphic.

Art is specified by two identifiers: the art identifier (wxArtID) and client identifier (wxArtClient). The client identifier is only a hint in case different windows need different graphics for the same art identifier. As an example, the wxHTML help window uses this code to get a bitmap for the Back toolbar button:

 wxBitmap bmp = wxArtProvider::GetBitmap(wxART_GO_BACK,wxART_TOOLBAR); 

You can browse the identifiers and graphics that are built into wxWidgets by compiling and running samples/artprov in your wxWidgets distribution. Figure 10-1 shows the browser in action.

Figure 10-1. Art resources browser


To provide your own replacements for wxWidgets art, simply derive a new class from wxArtProvider, override CreateBitmap, and call wxArtProvider::PushProvider from your application's OnInit function to make it known to wxWidgets. Here's an example that replaces most of the wxHTML help window artwork.

 // XPMs with the art #include "bitmaps/helpbook.xpm" #include "bitmaps/helppage.xpm" #include "bitmaps/helpback.xpm" #include "bitmaps/helpdown.xpm" #include "bitmaps/helpforward.xpm" #include "bitmaps/helpoptions.xpm" #include "bitmaps/helpsidepanel.xpm" #include "bitmaps/helpup.xpm" #include "bitmaps/helpuplevel.xpm" #include "bitmaps/helpicon.xpm" #include "wx/artprov.h" // The art provider class class MyArtProvider : public wxArtProvider { protected:     virtual wxBitmap CreateBitmap(const wxArtID& id,                                   const wxArtClient& client,                                   const wxSize& size); }; // CreateBitmap function wxBitmap MyArtProvider::CreateBitmap(const wxArtID& id,                                      const wxArtClient& client,                                      const wxSize& size) {     if (id == wxART_HELP_SIDE_PANEL)         return wxBitmap(helpsidepanel_xpm);     if (id == wxART_HELP_SETTINGS)         return wxBitmap(helpoptions_xpm);     if (id == wxART_HELP_BOOK)         return wxBitmap(helpbook_xpm);     if (id == wxART_HELP_FOLDER)         return wxBitmap(helpbook_xpm);     if (id == wxART_HELP_PAGE)         return wxBitmap(helppage_xpm);     if (id == wxART_GO_BACK)         return wxBitmap(helpback_xpm);     if (id == wxART_GO_FORWARD)         return wxBitmap(helpforward_xpm);     if (id == wxART_GO_UP)         return wxBitmap(helpup_xpm);     if (id == wxART_GO_DOWN)         return wxBitmap(helpdown_xpm);     if (id == wxART_GO_TO_PARENT)         return wxBitmap(helpuplevel_xpm);     if (id == wxART_FRAME_ICON)         return wxBitmap(helpicon_xpm);     if (id == wxART_HELP)         return wxBitmap(helpicon_xpm);     // Any wxWidgets icons not implemented here     // will be provided by the default art provider.     return wxNullBitmap;  } // Initialization bool MyApp::OnInit() {     ...     wxArtProvider::PushProvider(new MyArtProvider);     ...     return true; } 

    team bbl



    Cross-Platform GUI Programming with wxWidgets
    Cross-Platform GUI Programming with wxWidgets
    ISBN: 0131473816
    EAN: 2147483647
    Year: 2005
    Pages: 262

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net