FileTreeComponent - Changing Colours?


#1

Hello All. Could someone point me to the right direction on how to change the FileTreeComponent text colours? I can change the line and background colours, but not the selected and text colours.

Thanks for any help in advance. 8)


#2

Can’t remember offhand, but if you ever need to find out things like this, a quick look inside the class’s paint() methods should make it easy to see how it’s selecting the colour to use.


#3

Oh, thanks, I forgot to look into that. :oops:

Best Regards, WilliamK


#4

Ok, in any event, I decided to use the LookAndFeel so I could also make some of my own changes. :wink:

[code]class JUCE_API NewLookAndFeel : public LookAndFeel
{
public:
virtual void drawFileBrowserRow (Graphics& g, int width, int height,
const String& filename, Image* icon,
const String& fileSizeDescription,
const String& fileTimeDescription,
const bool isDirectory,
const bool isItemSelected,
const int itemIndex);
};

void NewLookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
const String& filename, Image* icon,
const String& fileSizeDescription,
const String& fileTimeDescription,
const bool isDirectory,
const bool isItemSelected,
const int /itemIndex/)
{
if (isItemSelected) g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
g.setFont (height * 0.7f);

int x = 0;

if (isDirectory)
{
	x = 32;
	Image* im = icon;
	Image* toRelease = 0;

	if (im == 0)
	{
		toRelease = im = getDefaultFolderImage();
	}

	if (im != 0)
	{
		g.drawImageWithin (im, 2, 2, x - 4, height - 4,
						   RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
						   false);

		ImageCache::release (toRelease);
	}
}

g.drawFittedText (filename, x, 0, width - x, height, Justification::centredLeft, 1);

}

#define SETcolour(ID,STRING) newLookAndFeel->setColour(ID, Colour::fromString( child->getStringAttribute(T(STRING),T(“000000”)) ))

			SETcolour(TreeView::backgroundColourId, "background");
			SETcolour(TreeView::linesColourId, "lines");
			SETcolour(DirectoryContentsDisplayComponent::textColourId, "text");
			SETcolour(DirectoryContentsDisplayComponent::highlightColourId, "highlight");

[/code]


#5

This works! 8)

I just need to figure out how to change the height of each item…

Wk


#6

Since I want to add more options to the tree-view, I wonder, shouldn’t I just go ahead and copy its whole code and create my own component?

I want to add an option so you can right-click on a file, rename, delete, move, … and for a folder, the same, plus, paste and create-new-folder.

But to be honest, I don’t know where to start, on making my own component, that would allow those mouse events.

I also didn’t figure out yet, how to create a call-back so I know when the user selects a new file. I guess I could create a thread that checks when something has changed, but I think that’s silly.

Sorry for so many basic questions, but the way I work, sometimes I overlook the simple stuff, but get the hardcore stuff right away…

Wk