Icons from arbitrary dir

Hello,

What is the way to use icons from directory different from $ROOTSYS/icons
in tool bar?

Hi Kirill,

You can specify the path where all GUI icons can be found in .rootrc file. Default settings are listed below:Gui.IconPath: $(HOME)/icons:$(ROOTSYS)/icons:.Cheers, Ilka

That is not what i need. My task is to provide some gui application with private icons.
I do not know which config is used on target hosts and i don’t have access to thier .rootrc.

Hello,
You can take a look at $ROOTSYS/test/RootShower, there is an example. The code looks like:

[code]const char *xpm_names[] = {
“open.xpm”,
“save.xpm”,
"",
“settings.xpm”,
"",
“infos.xpm”,
“view3d.xpm”,
"",
“browser.xpm”,
"",
“manual.xpm”,
“help.xpm”,
“license.xpm”,
“about.xpm”,
"",
“quit.xpm”,
0
};

[…]

int spacing = 8;
fToolBar = new TGToolBar(this, 60, 20, kHorizontalFrame | kRaisedFrame);
for (int i = 0; xpm_names[i]; i++) {
    TString iconname(gProgPath);
    iconname += "/icons/";
    iconname += xpm_names[i];
    tb_data[i].fPixmap = iconname.Data();
    if (strlen(xpm_names[i]) == 0) {
        spacing = 8;
        continue;
    }
    fToolBar->AddButton(this, &tb_data[i], spacing);
    spacing = 0;
}

[/code]HTH,
Bertrand.

Hi Kirill,

Your need was not evident from the first question. If you need to run your program on Windows, you will need to take care about iconname differently:#ifdef R__WIN32 iconname += "\\icons\\"; #else iconname += "/icons/"; #endif
Cheers, Ilka

Hi,
it’s possible to embed icons inside a program.

#include "myicon.xpm" // file containing   char *xpm_array[] 
TImage *img = TImage::Create();
img->SetImageBuffer(xpm_array, TImage::kXpm);
Pixmap_t pxmap = img->GetPixmap();
Pixmap_t mask =  img->GetMAsk();
const TGPicture *pic	= gClient->GetPicturePool()->GetPicture("myicon", pxmap, mask);
// now one can set an icon to some list view entry
list_view_entry->SetPictures(pic);
// or to set an icon for list tree item
list_tree_item->SetPictures(pic);
// or to some tool bar button
((TGPictureButton*)toolbar->GetButton(id))->SetPicture(pic);

Use ROOT CVS version. See also attached file for an example how to create an image
from embedded picture.

Regards. Valeriy
rose512jpg.C (376 KB)

Hi Valeriy

The only way i found to implement your suggestion so far is like that:


  b.fPixmap="ed_help.png"; b.fTipText="no"; b.fId++;b.fButton=0; tb->AddButton(this,&b,70);
#include "icons/iread.xpm"
  TImage *img = TImage::Create(); img->SetImageBuffer(iread, TImage::kXpm);
  ((TGPictureButton*)b.fButton)->SetPicture(gClient->GetPicturePool()->GetPicture("iconname",img->GetPixmap(),img->GetMask()));

So i need first to assign some picture from $ROOTSYS/icons and only then i’m able
to reassign the linked in picture. Is there a way to do the assignment directly?
Suppose i prepared the picture and registered it in the pool. No i have the pointer to it.
but if i just do b.fButton =new TGPictureButton(…)
and then tb->AddButton(this,&b), the code crashes.

OK, good point to GUI TODO list. Thanks.