1
0
forked from 0ad/0ad

Initial code for the Colour Tester tool.

This was SVN commit r2196.
This commit is contained in:
Ykkrosh 2005-04-29 18:46:48 +00:00
parent 7b9ba0c16d
commit c002228314
19 changed files with 1677 additions and 19 deletions

View File

@ -19,7 +19,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=".;..;.\General;.\CustomControls\EditableListCtrl;.\CustomControls\DraggableListCtrl;.\CustomControls\Windows;.\Misc;E:\wx\wxWidgets\include;E:\wx\wxWidgets\include\msvc"
AdditionalIncludeDirectories=".;..;.\General;.\CustomControls\EditableListCtrl;.\CustomControls\DraggableListCtrl;.\CustomControls\Windows;.\Misc;E:\wx\wxWidgets\include;E:\wx\wxWidgets\include\msvc;..\..\..\..\libraries\devil\src\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
@ -35,7 +35,7 @@
AdditionalDependencies="comctl32.lib rpcrt4.lib"
OutputFile="$(OutDir)/actored_d.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="E:\wx\wxWidgets\lib\vc_lib;E:\0ad\svnc\trunk\libraries\xerces\lib"
AdditionalLibraryDirectories="E:\wx\wxWidgets\lib\vc_lib;..\..\..\..\libraries\xerces\lib;..\..\..\..\libraries\devil\src\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/actored.pdb"
SubSystem="2"
@ -70,7 +70,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="1"
AdditionalIncludeDirectories=".;..;.\General;.\CustomControls\EditableListCtrl;.\CustomControls\DraggableListCtrl;.\CustomControls\Windows;.\Misc;E:\wx\wxWidgets\include;E:\wx\wxWidgets\include\msvc"
AdditionalIncludeDirectories=".;..;.\General;.\CustomControls\EditableListCtrl;.\CustomControls\DraggableListCtrl;.\CustomControls\Windows;.\Misc;E:\wx\wxWidgets\include;E:\wx\wxWidgets\include\msvc;..\..\..\..\libraries\devil\src\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
StringPooling="TRUE"
RuntimeLibrary="2"
@ -85,7 +85,7 @@
AdditionalDependencies="comctl32.lib rpcrt4.lib"
OutputFile="$(OutDir)/actored.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="E:\wx\wxWidgets\lib\vc_lib;E:\0ad\svnc\trunk\libraries\xerces\lib"
AdditionalLibraryDirectories="E:\wx\wxWidgets\lib\vc_lib;..\..\..\..\libraries\xerces\lib;..\..\..\..\libraries\devil\src\lib"
GenerateDebugInformation="FALSE"
SubSystem="2"
OptimizeReferences="2"
@ -233,6 +233,16 @@
RelativePath=".\CustomControls\Windows\AtlasWindow.h">
</File>
</Filter>
<Filter
Name="VirtualDirTreeCtrl"
Filter="">
<File
RelativePath=".\CustomControls\VirtualDirTreeCtrl\virtualdirtreectrl.cpp">
</File>
<File
RelativePath=".\CustomControls\VirtualDirTreeCtrl\virtualdirtreectrl.h">
</File>
</Filter>
</Filter>
<Filter
Name="ActorEditor"
@ -267,9 +277,15 @@
Filter="">
<File
RelativePath=".\Misc\actored.cpp">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"/>
</FileConfiguration>
</File>
<File
RelativePath=".\Misc\actored.h">
RelativePath=".\Misc\colourtest.cpp">
</File>
<File
RelativePath=".\Misc\stdafx.cpp">
@ -290,6 +306,34 @@
RelativePath=".\Misc\stdafx.h">
</File>
</Filter>
<Filter
Name="ColourTester"
Filter="">
<File
RelativePath=".\ColourTester\ColourTester.cpp">
</File>
<File
RelativePath=".\ColourTester\ColourTester.h">
</File>
<File
RelativePath=".\ColourTester\ColourTesterColourCtrl.cpp">
</File>
<File
RelativePath=".\ColourTester\ColourTesterColourCtrl.h">
</File>
<File
RelativePath=".\ColourTester\ColourTesterFileCtrl.cpp">
</File>
<File
RelativePath=".\ColourTester\ColourTesterFileCtrl.h">
</File>
<File
RelativePath=".\ColourTester\ColourTesterImageCtrl.cpp">
</File>
<File
RelativePath=".\ColourTester\ColourTesterImageCtrl.h">
</File>
</Filter>
</Filter>
<File
RelativePath=".\TODO.txt">

View File

@ -0,0 +1,50 @@
#include "stdafx.h"
#include "ColourTester.h"
#include "ColourTesterImageCtrl.h"
#include "ColourTesterColourCtrl.h"
#include "ColourTesterFileCtrl.h"
//#include "AtlasObject/AtlasObject.h"
//#include "Datafile.h"
//#include "wx/file.h"
BEGIN_EVENT_TABLE(ColourTester, wxFrame)
//EVT_MENU(ID_Custom1, OnCreateEntity)
END_EVENT_TABLE()
ColourTester::ColourTester(wxWindow* parent)
: wxFrame(parent, wxID_ANY, _("Colour Tester"), wxDefaultPosition, wxSize(800, 700))
{
wxPanel* mainPanel = new wxPanel(this);
//////////////////////////////////////////////////////////////////////////
// Set up sizers:
wxBoxSizer* vertSizer = new wxBoxSizer(wxVERTICAL);
mainPanel->SetSizer(vertSizer);
wxBoxSizer* topSizer = new wxBoxSizer(wxHORIZONTAL);
vertSizer->Add(topSizer,
wxSizerFlags().Proportion(1).Expand().Border(wxLEFT|wxRIGHT, 5));
wxBoxSizer* bottomSizer = new wxBoxSizer(wxHORIZONTAL);
vertSizer->Add(bottomSizer,
wxSizerFlags().Expand().Border(wxLEFT|wxRIGHT, 5));
//////////////////////////////////////////////////////////////////////////
// Add things to sizers:
m_ImageCtrl = new ColourTesterImageCtrl(mainPanel);
topSizer->Add(new ColourTesterFileCtrl(mainPanel, wxSize(200,200), m_ImageCtrl),
wxSizerFlags().Expand().Border(wxALL, 10));
topSizer->Add(m_ImageCtrl,
wxSizerFlags().Proportion(1).Expand().Border(wxALL, 10));
bottomSizer->Add((wxPanel*)new ColourTesterColourCtrl(mainPanel, m_ImageCtrl),
wxSizerFlags().Border(wxALL, 10));
}

View File

@ -0,0 +1,12 @@
class ColourTesterImageCtrl;
class ColourTester : public wxFrame
{
public:
ColourTester(wxWindow* parent);
private:
ColourTesterImageCtrl* m_ImageCtrl;
DECLARE_EVENT_TABLE();
};

View File

@ -0,0 +1,95 @@
#include "stdafx.h"
#include "ColourTesterColourCtrl.h"
#include "ColourTesterImageCtrl.h"
//////////////////////////////////////////////////////////////////////////
// A couple of buttons:
class ColouredButton : public wxButton
{
public:
ColouredButton(wxWindow* parent, int colour[], const wxString& caption, ColourTesterImageCtrl* imgctrl)
: wxButton(parent, wxID_ANY, caption),
m_ImageCtrl(imgctrl), m_Colour(colour[0], colour[1], colour[2])
{
SetBackgroundColour(m_Colour);
// TODO: More readable text colours
}
void OnButton(wxCommandEvent& WXUNUSED(event))
{
m_ImageCtrl->SetColour(m_Colour);
}
private:
wxColour m_Colour;
ColourTesterImageCtrl* m_ImageCtrl;
DECLARE_EVENT_TABLE();
};
BEGIN_EVENT_TABLE(ColouredButton, wxButton)
EVT_BUTTON(wxID_ANY, ColouredButton::OnButton)
END_EVENT_TABLE()
class CustomColourButton : public wxButton
{
public:
CustomColourButton(wxWindow* parent, const wxString& caption, ColourTesterImageCtrl* imgctrl)
: wxButton(parent, wxID_ANY, caption),
m_ImageCtrl(imgctrl), m_Colour(127,127,127)
{
SetBackgroundColour(m_Colour);
}
void OnButton(wxCommandEvent& WXUNUSED(event))
{
wxColour c = wxGetColourFromUser(this, m_Colour);
if (c.Ok())
{
m_Colour = c;
m_ImageCtrl->SetColour(m_Colour);
SetBackgroundColour(m_Colour);
}
}
private:
wxColour m_Colour;
ColourTesterImageCtrl* m_ImageCtrl;
DECLARE_EVENT_TABLE();
};
BEGIN_EVENT_TABLE(CustomColourButton, wxButton)
EVT_BUTTON(wxID_ANY, CustomColourButton::OnButton)
END_EVENT_TABLE()
//////////////////////////////////////////////////////////////////////////
ColourTesterColourCtrl::ColourTesterColourCtrl(wxWindow* parent, ColourTesterImageCtrl* imgctrl)
: wxPanel(parent, wxID_ANY)
{
wxBoxSizer* mainSizer = new wxBoxSizer(wxHORIZONTAL);
wxGridSizer* presetColourSizer = new wxGridSizer(2);
mainSizer->Add(presetColourSizer);
// TODO: make configurable
int presetColours[][3] = {
{255,255,255}, // Gaia
{255,0,0}, // Player 1
{0,255,0}, // etc
{0,0,255},
{255,255,0},
{255,0,255},
{0,255,255},
{255,127,255},
{255,204,127}
};
for (int i = 0; i < sizeof(presetColours)/sizeof(presetColours[0]); ++i)
{
wxButton* button = new ColouredButton(this, presetColours[i],
i ? wxString::Format(_("Player %d"), i) : _("Gaia"), imgctrl);
presetColourSizer->Add(button);
}
presetColourSizer->Add(new CustomColourButton(this, _("Custom"), imgctrl));
SetSizer(mainSizer);
mainSizer->SetSizeHints(this);
}

View File

@ -0,0 +1,7 @@
class ColourTesterImageCtrl;
class ColourTesterColourCtrl : public wxPanel
{
public:
ColourTesterColourCtrl(wxWindow* parent, ColourTesterImageCtrl* imgctrl);
};

View File

@ -0,0 +1,28 @@
#include "stdafx.h"
#include "ColourTesterFileCtrl.h"
#include "Datafile.h"
#include "ColourTesterImageCtrl.h"
BEGIN_EVENT_TABLE(ColourTesterFileCtrl, wxVirtualDirTreeCtrl)
EVT_TREE_SEL_CHANGED(wxID_ANY, ColourTesterFileCtrl::OnSelChanged)
END_EVENT_TABLE()
ColourTesterFileCtrl::ColourTesterFileCtrl(wxWindow* parent, const wxSize& size, ColourTesterImageCtrl* imgctrl)
: wxVirtualDirTreeCtrl(parent, wxID_ANY, wxDefaultPosition, size),
m_ImageCtrl(imgctrl)
{
wxFileName path (_T("../data/mods/official/art/textures/skins/"));
path.MakeAbsolute(Datafile::GetSystemDirectory());
wxASSERT(path.IsOk());
SetRootPath(path.GetPath());
}
void ColourTesterFileCtrl::OnSelChanged(wxTreeEvent& event)
{
if (IsFileNode(event.GetItem()))
{
m_ImageCtrl->SetImageFile(GetFullPath(event.GetItem()));
}
}

View File

@ -0,0 +1,20 @@
#include "CustomControls/VirtualDirTreeCtrl/virtualdirtreectrl.h"
// wxGenericDirCtrl could potentially be used instead of this; but it gets
// indented a long way (since its root is far further back than necessary),
// and its icons aren't very pretty, and it'd be hard to adjust it to use VFS.
class ColourTesterImageCtrl;
class ColourTesterFileCtrl : public wxVirtualDirTreeCtrl
{
public:
ColourTesterFileCtrl(wxWindow* parent, const wxSize& size, ColourTesterImageCtrl* imgctrl);
private:
void OnSelChanged(wxTreeEvent& event);
ColourTesterImageCtrl* m_ImageCtrl;
DECLARE_EVENT_TABLE();
};

View File

@ -0,0 +1,125 @@
#include "stdafx.h"
#include "ColourTesterImageCtrl.h"
#ifdef _MSC_VER
# ifndef NDEBUG
# pragma comment(lib, "DevIL_DBG.lib")
# pragma comment(lib, "DevILU_DBG.lib")
# else
# pragma comment(lib, "DevIL.lib")
# pragma comment(lib, "DevILU.lib")
# endif
#endif
#include "IL/il.h"
#include "IL/ilu.h"
BEGIN_EVENT_TABLE(ColourTesterImageCtrl, wxWindow)
EVT_PAINT(ColourTesterImageCtrl::OnPaint)
END_EVENT_TABLE()
ColourTesterImageCtrl::ColourTesterImageCtrl(wxWindow* parent)
: wxWindow(parent, wxID_ANY),
m_Valid(false), m_ZoomAmount(1)
{
m_Colour[0] = 255;
m_Colour[1] = 0;
m_Colour[2] = 0;
ilInit();
ilGenImages(1, (ILuint*)&m_OriginalImage);
}
void ColourTesterImageCtrl::SetImageFile(const wxFileName& fn)
{
ilBindImage(m_OriginalImage);
ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
ilEnable(IL_ORIGIN_SET);
if (! ilLoadImage((TCHAR*)fn.GetFullPath().c_str()))
{
m_Valid = false;
Refresh();
return;
}
m_Valid = true;
ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
// TODO: Check for IL errors
{
// I'm too lazy to add zoom buttons, so just use 2x zoom for <=256x256 images
ILinfo info;
iluGetImageInfo(&info);
if (info.Width <= 256 && info.Height <= 256)
m_ZoomAmount = 2;
else
m_ZoomAmount = 1;
}
CalculateImage();
}
void ColourTesterImageCtrl::SetColour(const wxColour& colour)
{
m_Colour[0] = colour.Red();
m_Colour[1] = colour.Green();
m_Colour[2] = colour.Blue();
CalculateImage();
}
void ColourTesterImageCtrl::SetZoom(int amount)
{
m_ZoomAmount = amount;
CalculateImage();
}
void ColourTesterImageCtrl::CalculateImage()
{
if (! m_Valid)
return;
ilBindImage(m_OriginalImage);
ILubyte* data = ilGetData();
ILinfo info;
iluGetImageInfo(&info);
wxASSERT(info.Bpp == 4);
unsigned char* newData = (unsigned char*)malloc(info.Width*info.Height*3);
// wxImage desires malloc, not new[]
for (ILubyte *p0 = data, *p1 = newData;
p0 < data+info.Width*info.Height*4;
p0 += 4, p1 += 3)
{
// Interpolate between texture and colour, so
// new = old*alpha + colour*(1-alpha)
float alpha = p0[3]/255.f;
p1[0] = p0[0] * alpha + m_Colour[0]*(1.f-alpha);
p1[1] = p0[1] * alpha + m_Colour[1]*(1.f-alpha);
p1[2] = p0[2] * alpha + m_Colour[2]*(1.f-alpha);
}
m_FinalImage.SetData(newData, info.Width, info.Height);
if (m_ZoomAmount != 1)
m_FinalImage = m_FinalImage.Scale(info.Width*m_ZoomAmount, info.Height*m_ZoomAmount);
m_FinalBitmap = wxBitmap(m_FinalImage);
Refresh();
}
void ColourTesterImageCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
{
wxPaintDC dc(this);
dc.Clear();
if (m_Valid && m_FinalBitmap.Ok())
dc.DrawBitmap(m_FinalBitmap, 0, 0);
}

View File

@ -0,0 +1,27 @@
#include "wx/image.h"
class ColourTesterImageCtrl : public wxWindow
{
public:
ColourTesterImageCtrl(wxWindow* parent);
void SetImageFile(const wxFileName& fn);
void SetColour(const wxColour& colour);
void SetZoom(int amount);
void OnPaint(wxPaintEvent& event);
private:
void CalculateImage();
bool m_Valid; // stores whether a valid image is loaded and displayable
unsigned int m_OriginalImage; // DevIL image id
wxImage m_FinalImage;
wxBitmap m_FinalBitmap;
unsigned char m_Colour[3]; // RGB bytes
int m_ZoomAmount;
DECLARE_EVENT_TABLE();
};

View File

@ -0,0 +1,3 @@
wxVirtualDirTreeCtrl (v1.0b) from http://www.solidsteel.nl/jorg/components/virtualdirtreectrl/wxVirtualDirTreeCtrl.php
"wxVirtualDirTreeCtrl is freeware and distributed under the wxWidgets license."

View File

@ -0,0 +1,36 @@
/* XPM */
static char *xpm_file[] = {
"16 16 16 2",
"00 c black",
"01 c #848484",
"02 c #D6D6CE",
"03 c gray100",
"04 c none",
"05 c gray100",
"06 c gray100",
"07 c gray100",
"08 c gray100",
"09 c gray100",
"10 c gray100",
"11 c gray100",
"12 c gray100",
"13 c gray100",
"14 c gray100",
"15 c gray100",
"04040404040404040404040404040404",
"04040101010101010101010104040404",
"04040103030303030303030001040404",
"04040103030303030303030002010404",
"04040103030000000000030000000004",
"04040103030303030303030303030004",
"04040103030000000000000003030004",
"04040103030303030303030303030004",
"04040103030000000000000003030004",
"04040103030303030303030303030004",
"04040103030000000000000003030004",
"04040103030303030303030303030004",
"04040103030000000000000003030004",
"04040103030303030303030303030004",
"04040103030303030303030303030004",
"04040000000000000000000000000004"
};

View File

@ -0,0 +1,36 @@
/* XPM */
static char *xpm_folder[] = {
"16 16 16 2",
"00 c #A06B04",
"01 c #B17B14",
"02 c #C18C25",
"03 c #CE9831",
"04 c gray29",
"05 c #777777",
"06 c gray55",
"07 c none",
"08 c #ECB94F",
"09 c #FFE178",
"10 c #FFF388",
"11 c #FFFB98",
"12 c #CECECE",
"13 c #DADADA",
"14 c gray97",
"15 c gray100",
"07070707070707070707070707070707",
"07070303030313140707070707070707",
"07031515151502121407070707070707",
"03151111111115020202010101131407",
"03111010101010151515151501061307",
"03100902020202020202020201010113",
"03090215151515151515151509150006",
"02090311111111111111111108110005",
"02090311111111111111111108110005",
"02090211101010101010101008110005",
"02090211090909090909090908110005",
"02090211090909090909090903110005",
"13010101010101000000000000000406",
"14120605050505050505050505050612",
"07141313131313131313131313131314",
"07070707070707070707070707070707"
};

View File

@ -0,0 +1,36 @@
/* XPM */
static char *xpm_root[] = {
"16 16 16 2",
"00 c #976911",
"01 c gray42",
"02 c #C18B24",
"03 c #E3B552",
"04 c #6482B3",
"05 c #8E9CAA",
"06 c #FFEE86",
"07 c gray74",
"08 c #68BDFF",
"09 c #B9CDE6",
"10 c #D2D2D2",
"11 c #D8E9F1",
"12 c #E7F7FF",
"13 c #F3F7FB",
"14 c #F7FFFF",
"15 c none",
"15151515040404040404040811131515",
"15151515041313131313130808101315",
"15150202041309090909130808081013",
"15021313041313131313131111040111",
"02130606041209090909090912040110",
"02060606041212121212121212040110",
"02060202040707070707070707040207",
"02060213111313131313131313110001",
"02060206071109090909090911070001",
"02030206071111111111111111070001",
"02030206071111111111111111070001",
"02030206070707070707070707070001",
"02030206060303030303030303060001",
"11020202020000000000000000000101",
"13100101010101010101010101010110",
"15131110101010101010101010101113"
};

View File

@ -0,0 +1,619 @@
#include "stdafx.h"
/////////////////////////////////////////////////////////////////////////////
// Name: wxVirtualDirTreeCtrl.cpp
// Author: XX
// Created: Saturday, March 27, 2004 14:15:56
// Copyright: XX
/////////////////////////////////////////////////////////////////////////////
//#ifdef __GNUG__
// #pragma implementation "wxVirtualDirTreeCtrl.cpp"
//#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include <wx/dir.h>
#include <wx/busyinfo.h>
#include "virtualdirtreectrl.h"
// default images
#include "folder.xpm"
#include "file.xpm"
#include "root.xpm"
// WDR: class implementations
//----------------------------------------------------------------------------
// wxVirtualDirTreeCtrl
//----------------------------------------------------------------------------
// WDR: event table for wxVirtualDirTreeCtrl
BEGIN_EVENT_TABLE(wxVirtualDirTreeCtrl, wxTreeCtrl)
EVT_TREE_ITEM_EXPANDING(-1, wxVirtualDirTreeCtrl::OnExpanding)
END_EVENT_TABLE()
wxVirtualDirTreeCtrl::wxVirtualDirTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name)
: wxTreeCtrl(parent, id, pos, size, style, validator, name)
, _flags(wxVDTC_DEFAULT)
{
// create an icon list for the tree ctrl
_iconList = new wxImageList(16,16);
// reset to default extension list
ResetExtensions();
}
wxVirtualDirTreeCtrl::~wxVirtualDirTreeCtrl()
{
// first delete all VdtcTreeItemBase items (client data)
DeleteAllItems();
// delete the icons
delete _iconList;
}
bool wxVirtualDirTreeCtrl::SetRootPath(const wxString &root, int flags)
{
bool value;
wxBusyInfo *bsy = 0;
wxLogNull log;
// set flags to adopt new behaviour
_flags = flags;
// delete all items plus root first
DeleteAllItems();
VdtcTreeItemBase *start = 0;
// now call for icons management, the virtual
// handler so the derived class can assign icons
_iconList->RemoveAll();
OnAssignIcons(*_iconList);
SetImageList(_iconList);
value = ::wxDirExists(root);
if(value)
{
// call virtual handler to notify the derived class
OnSetRootPath(root);
// create a root item
start = OnCreateTreeItem(VDTC_TI_ROOT, root);
if(start)
{
wxFileName path;
path.AssignDir(root);
// call the add callback and find out if this root
// may be added (later on)
if(OnAddRoot(*start, path))
{
// add this item to the tree, with info of the developer
wxTreeItemId id = AddRoot(start->GetCaption(), start->GetIconId(), start->GetSelectedIconId(), start);
// show a busy dialog
if(_flags & (wxVDTC_RELOAD_ALL | wxVDTC_SHOW_BUSYDLG))
bsy = new wxBusyInfo(_("Please wait, scanning directory..."), 0);
// scan directory, either the smart way or not at all
ScanFromDir(start, path, (wxVDTC_RELOAD_ALL & _flags ? -1 : VDTC_MIN_SCANDEPTH));
// expand root when allowed
if(!(_flags & wxVDTC_NO_EXPAND))
Expand(id);
}
else
delete start; // sorry not succeeded
}
}
// delete busy info if present
if(bsy)
delete bsy;
return value;
}
int wxVirtualDirTreeCtrl::ScanFromDir(VdtcTreeItemBase *item, const wxFileName &path, int level)
{
int value = 0;
wxCHECK(item, -1);
wxCHECK(item->IsDir() || item->IsRoot(), -1);
wxLogNull log;
// when we can still scan, do so
if(level == -1 || level > 0)
{
// TODO: Maybe when a reload is issued, delete all items that are no longer present
// in the tree (on disk) and check if all new items are present, else add them
// if no items, then go iterate and get everything in this branch
if(GetChildrenCount(item->GetId()) == 0)
{
VdtcTreeItemBaseArray addedItems;
// now call handler, if allowed, scan this dir
if(OnDirectoryScanBegin(path))
{
// get directories
GetDirectories(item, addedItems, path);
// get files
if(!(_flags & wxVDTC_NO_FILES))
GetFiles(item, addedItems, path);
// call handler that can do a last thing
// before sort and anything else
OnDirectoryScanEnd(addedItems, path);
// sort items
if(addedItems.GetCount() > 0 && (_flags & wxVDTC_NO_SORT) == 0)
SortItems(addedItems, 0, (int)addedItems.GetCount()-1);
AddItemsToTreeCtrl(item, addedItems);
// call handler to tell that the items are on the tree ctrl
OnAddedItems(item);
}
}
value = (int)GetChildrenCount(item->GetId());
// go through all children of this node, pick out all
// the dir classes, and descend as long as the level allows it
// NOTE: Don't use the addedItems array, because some new can
// be added or some can be deleted.
wxTreeItemIdValue cookie = 0;
VdtcTreeItemBase *b;
wxTreeItemId child = GetFirstChild(item->GetId(), cookie);
while(child.IsOk())
{
b = (VdtcTreeItemBase *)GetItemData(child);
if(b && b->IsDir())
{
wxFileName tp = path;
tp.AppendDir(b->GetName());
value += ScanFromDir(b, tp, (level == -1 ? -1 : level-1));
}
child = GetNextChild(item->GetId(), cookie);
}
}
return value;
}
void wxVirtualDirTreeCtrl::GetFiles(VdtcTreeItemBase *WXUNUSED(parent), VdtcTreeItemBaseArray &items, const wxFileName &path)
{
wxFileName fpath;
wxString fname;
VdtcTreeItemBase *item;
fpath = path;
// no nodes present yet, we should start scanning this dir
// scan files first in this directory, with all extensions in this array
for(size_t i = 0; i < _extensions.Count(); i++)
{
wxDir fdir(path.GetFullPath());
if(fdir.IsOpened())
{
bool bOk = fdir.GetFirst(&fname, _extensions[i], wxDIR_FILES | wxDIR_HIDDEN);
while(bOk)
{
// TODO: Flag for double items
item = AddFileItem(fname);
if(item)
{
// fill it in, and marshall it by the user for info
fpath.SetFullName(fname);
if(OnAddFile(*item, fpath))
items.Add(item);
else
delete item;
}
bOk = fdir.GetNext(&fname);
}
}
}
}
void wxVirtualDirTreeCtrl::GetDirectories(VdtcTreeItemBase *WXUNUSED(parent), VdtcTreeItemBaseArray &items, const wxFileName &path)
{
wxFileName fpath;
wxString fname;
VdtcTreeItemBase *item;
// no nodes present yet, we should start scanning this dir
// scan files first in this directory, with all extensions in this array
wxDir fdir(path.GetFullPath());
if(fdir.IsOpened())
{
bool bOk = fdir.GetFirst(&fname, VDTC_DIR_FILESPEC, wxDIR_DIRS | wxDIR_HIDDEN);
while(bOk)
{
// TODO: Flag for double items
item = AddDirItem(fname);
if(item)
{
// fill it in, and marshall it by the user for info
fpath = path;
fpath.AppendDir(fname);
if(OnAddDirectory(*item, fpath))
items.Add(item);
else
delete item;
}
bOk = fdir.GetNext(&fname);
}
}
}
int wxVirtualDirTreeCtrl::OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2)
{
// used for SortChildren, reroute to our sort routine
VdtcTreeItemBase *a = (VdtcTreeItemBase *)GetItemData(item1),
*b = (VdtcTreeItemBase *)GetItemData(item2);
if(a && b)
return OnCompareItems(a,b);
return 0;
}
int wxVirtualDirTreeCtrl::OnCompareItems(const VdtcTreeItemBase *a, const VdtcTreeItemBase *b)
{
// if dir and other is not, dir has preference
if(a->IsDir() && b->IsFile())
return -1;
else if(a->IsFile() && b->IsDir())
return 1;
// else let ascii fight it out
return a->GetCaption().CmpNoCase(b->GetCaption());
}
void wxVirtualDirTreeCtrl::SwapItem(VdtcTreeItemBaseArray &items, int a, int b)
{
VdtcTreeItemBase *t = items[b];
items[b] = items[a];
items[a] = t;
}
void wxVirtualDirTreeCtrl::SortItems(VdtcTreeItemBaseArray &items, int left, int right)
{
VdtcTreeItemBase *a, *b;
int i, last;
if(left >= right)
return;
SwapItem(items, left, (left + right)/2);
last = left;
for(i = left+1; i <= right; i++)
{
a = items[i];
b = items[left];
if(a && b)
{
if(OnCompareItems(a, b) < 0)
SwapItem(items, ++last, i);
}
}
SwapItem(items, left, last);
SortItems(items, left, last-1);
SortItems(items, last+1, right);
}
void wxVirtualDirTreeCtrl::AddItemsToTreeCtrl(VdtcTreeItemBase *item, VdtcTreeItemBaseArray &items)
{
wxCHECK2(item, return);
// now loop through all elements on this level and add them
// to the tree ctrl pointed out by 'id'
VdtcTreeItemBase *t;
wxTreeItemId id = item->GetId();
for(size_t i = 0; i < items.GetCount(); i++)
{
t = items[i];
if(t)
AppendItem(id, t->GetCaption(), t->GetIconId(), t->GetSelectedIconId(), t);
}
}
wxFileName wxVirtualDirTreeCtrl::GetRelativePath(const wxTreeItemId &id)
{
wxFileName value;
wxCHECK(id.IsOk(), value);
VdtcTreeItemBase *b = (VdtcTreeItemBase *)GetItemData(id);
wxCHECK(b, value);
AppendPathRecursively(b, value, false);
return value;
}
wxFileName wxVirtualDirTreeCtrl::GetFullPath(const wxTreeItemId &id)
{
wxFileName value;
wxCHECK(id.IsOk(), value);
VdtcTreeItemBase *b = (VdtcTreeItemBase *)GetItemData(id);
wxCHECK(b, value);
AppendPathRecursively(b, value, true);
return value;
}
wxTreeItemId wxVirtualDirTreeCtrl::ExpandToPath(const wxFileName &path)
{
wxTreeItemId value((void *)0);
wxFileName seekpath;
wxArrayString paths;
VdtcTreeItemBase *ptr;
paths = path.GetDirs();
// start in root section, and find the path sections that
// match the sequence
wxTreeItemId root = GetRootItem();
if(root.IsOk())
{
wxTreeItemId curr = root, id;
for(size_t i = 0; i < paths.GetCount(); i++)
{
// scan for name on this level of children
wxString currpath = paths[i];
bool not_found = true;
wxTreeItemIdValue cookie;
id = GetFirstChild(curr, cookie);
while(not_found && id.IsOk())
{
ptr = (VdtcTreeItemBase *)GetItemData(id);
not_found = !ptr->GetName().IsSameAs(currpath, false);
// prevent overwriting id
if(!not_found)
{
// we found the name, now to ensure there are more
// names loaded from disk, we call ScanFromDir (it will abort anywayz
// when there are items in the dir)
if(ptr->IsDir())
{
// TODO: This getfullpath might be a too high load, we can also
// walk along with the path, but that is a bit more tricky.
seekpath = GetFullPath(id);
ScanFromDir(ptr, seekpath, VDTC_MIN_SCANDEPTH);
}
curr = id;
}
else
id = GetNextChild(curr, cookie);
}
// now, if not found we break out
if(not_found)
return value;
}
// when we are here we are at the final node
Expand(curr);
value = curr;
}
return value;
}
bool wxVirtualDirTreeCtrl::IsRootNode(const wxTreeItemId &id)
{
bool value = false;
wxCHECK(id.IsOk(), value);
VdtcTreeItemBase *b = (VdtcTreeItemBase *)GetItemData(id);
if(b)
value = b->IsRoot();
return value;
}
bool wxVirtualDirTreeCtrl::IsDirNode(const wxTreeItemId &id)
{
bool value = false;
wxCHECK(id.IsOk(), value);
VdtcTreeItemBase *b = (VdtcTreeItemBase *)GetItemData(id);
if(b)
value = b->IsDir();
return value;
}
bool wxVirtualDirTreeCtrl::IsFileNode(const wxTreeItemId &id)
{
bool value = false;
wxCHECK(id.IsOk(), value);
VdtcTreeItemBase *b = (VdtcTreeItemBase *)GetItemData(id);
if(b)
value = b->IsFile();
return value;
}
/** Appends subdirs up until root. This is done by finding the root first and
going back down to the original caller. This is faster because no copying takes place */
void wxVirtualDirTreeCtrl::AppendPathRecursively(VdtcTreeItemBase *b, wxFileName &dir, bool useRoot)
{
wxCHECK2(b, return);
VdtcTreeItemBase *parent = GetParent(b);
if(parent)
AppendPathRecursively(parent, dir, useRoot);
else
{
// no parent assume top node
if(b->IsRoot() && useRoot)
dir.AssignDir(b->GetName());
return;
}
// now we are unwinding the other way around
if(b->IsDir())
dir.AppendDir(b->GetName());
else if(b->IsFile())
dir.SetFullName(b->GetName());
};
// -- event handlers --
void wxVirtualDirTreeCtrl::OnExpanding(wxTreeEvent &event)
{
// check for collapsing item, and scan from there
wxTreeItemId id = event.GetItem();
if(id.IsOk())
{
VdtcTreeItemBase *t = (VdtcTreeItemBase *)GetItemData(id);
if(t && t->IsDir())
{
// extract data element belonging to it, and scan.
ScanFromDir(t, GetFullPath(id), VDTC_MIN_SCANDEPTH);
// TODO: When this scan gives no nodes, delete all children
// and conclude that the scan could not be performed upon expansion
}
}
// be kind, and let someone else also handle this event
event.Skip();
}
wxBitmap *wxVirtualDirTreeCtrl::CreateRootBitmap()
{
// create root and return
return new wxBitmap(xpm_root);
}
wxBitmap *wxVirtualDirTreeCtrl::CreateFolderBitmap()
{
// create folder and return
return new wxBitmap(xpm_folder);
}
wxBitmap *wxVirtualDirTreeCtrl::CreateFileBitmap()
{
// create file and return
return new wxBitmap(xpm_file);
}
VdtcTreeItemBase *wxVirtualDirTreeCtrl::AddFileItem(const wxString &name)
{
// call the file item node create method
return OnCreateTreeItem(VDTC_TI_FILE, name);
}
VdtcTreeItemBase *wxVirtualDirTreeCtrl::AddDirItem(const wxString &name)
{
// call the dir item node create method
return OnCreateTreeItem(VDTC_TI_DIR, name);
}
// --- virtual handlers ----
void wxVirtualDirTreeCtrl::OnAssignIcons(wxImageList &icons)
{
wxBitmap *bmp;
// default behaviour, assign three bitmaps
bmp = CreateRootBitmap();
icons.Add(*bmp);
delete bmp;
// 1 = folder
bmp = CreateFolderBitmap();
icons.Add(*bmp);
delete bmp;
// 2 = file
bmp = CreateFileBitmap();
icons.Add(*bmp);
delete bmp;
}
VdtcTreeItemBase *wxVirtualDirTreeCtrl::OnCreateTreeItem(int type, const wxString &name)
{
// return a default instance, no extra info needed in this item
return new VdtcTreeItemBase(type, name);
}
bool wxVirtualDirTreeCtrl::OnAddRoot(VdtcTreeItemBase &WXUNUSED(item), const wxFileName &WXUNUSED(name))
{
// allow adding
return true;
}
bool wxVirtualDirTreeCtrl::OnDirectoryScanBegin(const wxFileName &WXUNUSED(path))
{
// allow all paths
return true;
}
bool wxVirtualDirTreeCtrl::OnAddFile(VdtcTreeItemBase &WXUNUSED(item), const wxFileName &WXUNUSED(name))
{
// allow all files
return true;
}
bool wxVirtualDirTreeCtrl::OnAddDirectory(VdtcTreeItemBase &WXUNUSED(item), const wxFileName &WXUNUSED(name))
{
// allow all dirs
return true;
}
void wxVirtualDirTreeCtrl::OnSetRootPath(const wxString &WXUNUSED(root))
{
// do nothing here, but it can be used to start initialisation
// based upon the setting of the root (which means a renewal from the tree)
}
void wxVirtualDirTreeCtrl::OnAddedItems(const wxTreeItemId &WXUNUSED(parent))
{
return;
}
void wxVirtualDirTreeCtrl::OnDirectoryScanEnd(VdtcTreeItemBaseArray &WXUNUSED(items), const wxFileName &WXUNUSED(path))
{
return;
}

View File

@ -0,0 +1,471 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wxVirtualDirTreeCtrl.h
// Author: XX
// Created: Saturday, March 27, 2004 14:15:56
// Copyright: XX
/////////////////////////////////////////////////////////////////////////////
#ifndef __WXVIRTUALDIRTREECTRL_H__
#define __WXVIRTUALDIRTREECTRL_H__
//#ifdef __GNUG__
// #pragma interface "virtualdirtreectrl.cpp"
//#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include <wx/dynarray.h>
#include <wx/treectrl.h>
#include <wx/filesys.h>
#include <wx/imaglist.h>
enum
{
VDTC_TI_ROOT = 0,
VDTC_TI_DIR,
VDTC_TI_FILE
};
#ifndef LINUX
#define VDTC_DIR_FILESPEC _T("*.*")
#else
#define VDTC_DIR_FILESPEC _T("*")
#endif
/// Icon number for root
#define VDTC_ICON_ROOT 0
/// Icon number for a folder
#define VDTC_ICON_DIR 1
/// Icon number for file
#define VDTC_ICON_FILE 2
/// Minimal amount of levels to scan per run
#define VDTC_MIN_SCANDEPTH 2
/// No settings, take default
#define wxVDTC_DEFAULT 0
/** Instead of performing a smart reload per collapsed node, all items are loaded
into memory. NOTE: This can take a while! */
#define wxVDTC_RELOAD_ALL 1
/** Show a busy dialog to inform user, only valid when wxVDTC_RELOAD_ALL is set. Showing
a busy dialog on every smart expansion is not useful anyway */
#define wxVDTC_SHOW_BUSYDLG 2
/// Do not expand the root node after reloading
#define wxVDTC_NO_EXPAND 4
/// Do not call sort. Simply display files as they are located
#define wxVDTC_NO_SORT 8
/// Do not add files, only directories
#define wxVDTC_NO_FILES 16
/** \class VdtcTreeItemBase
This class is used to link the information of a file/root or folder node to a wxTreeItem
in the wxTreeCtrl.
To use more information in this class, inherit this with your own copy, and in the handler
wxVirtualDirTreeCtrl::OnCreateTreeItem, return your own class. This allows you to store more
information in this class.
For example; to return a different caption instead of the standard filename / directory, inherit this, and
redefine the VdtcTreeItemBase::GetCaption() member. The same goes for the VdtcTreeItemBase::GetIconId()
and VdtcTreeItemBase::GetSelectedIconId() functions if you redefined the bitmaps in the imagelist.
*/
class VdtcTreeItemBase : public wxTreeItemData
{
protected:
wxString _name;
int _type;
public:
/** Default constructor. Pass the parent of this node as a VdtcTreeItemBase object, the type
of this object (VDTC_TI_ROOT,VDTC_TI_DIR, VDTC_TI_FILE or added types but leave these
three in place), and the name of the object (i.e. filename or dir name). When deriving this
class make sure you call the constructor propertly. The types are of essence for some
internal functions. For example:
\code
class MyOwnData : public VdtcTreeItemBase
{
MyOwnData(int type, const wxString &name)
: VdtcTreeItemBase(type, name)
{
// do initialisation
}
}
\endcode
*/
VdtcTreeItemBase(int type, const wxString &name)
: _type(type)
, _name(name)
{
};
/** Default destructor */
~VdtcTreeItemBase()
{
// NOTE: do not delete the tree item
// because the tree item deletes this item data
};
/** Virtual function to report the caption back to the wxTreeCtrl to be added. If the caption should be
something else then the default name it gets from the file (or the root path when this node points
to a root item, inherit this class and redefine GetCaption
*/
virtual const wxString &GetCaption() const {
return _name;
};
/** Virtual function to return the icon ID this node should get. Per default it gets the ID of the
default image list. If you assigned more bitmaps (or different bitmaps) to the image list, return
the proper indices based upon the class it refers to. The ID's returned are:
- VDTC_ICON_ROOT: For root
- VDTC_ICON_DIR: For a directory
- VDTC_ICON_FILE: For a file
*/
virtual int GetIconId() const {
switch(_type)
{
case VDTC_TI_ROOT:
return VDTC_ICON_ROOT;
case VDTC_TI_DIR:
return VDTC_ICON_DIR;
case VDTC_TI_FILE:
return VDTC_ICON_FILE;
}
return -1;
};
/** Virtual function to return the selected icon ID this node should get. Per default there is no icon
associated with a selection. If you would like a selection, inherit this class and redefine this function
to return a proper id.
*/
virtual int GetSelectedIconId() const {
return -1;
};
/** Gets this name. The name of the root is the base path of the whole directory, the
name of a file node is the filename, and from a dir node the directory name.
\sa IsDir, IsFile, IsRoot */
const wxString &GetName() {
return _name;
};
/** Returns true if this is of type VDTC_TI_DIR */
bool IsDir() const {
return _type == VDTC_TI_DIR;
};
/** Returns true if this is of type VDTC_TI_ROOT */
bool IsRoot() const {
return _type == VDTC_TI_ROOT;
};
/** Returns true if this is of type VDTC_TI_FILE */
bool IsFile() const {
return _type == VDTC_TI_FILE;
};
};
// the formal definition of the array of pointers for tree item base
WX_DEFINE_ARRAY(VdtcTreeItemBase *, VdtcTreeItemBaseArray);
/**
\class wxVirtualDirTreeCtrl
A class which allows the user to browse through a 'virtual' treectrl, fully customizable when it's derived.
The wxVirtualDirTreeCtrl can be used for displaying the directory structure in a tree ctrl just like the
wxDirCtrl, but has much more advantages and flexibility for the developer. A list of some of the functionality
embedded:
See the main page to read more about this control.
*/
class wxVirtualDirTreeCtrl : public wxTreeCtrl
{
private:
/** File extensions list */
wxArrayString _extensions;
/** Icons image list */
wxImageList *_iconList;
/** Extra flags */
int _flags;
/** Scans from given dir, for 'level' depth and with present extensions. This will
reload the directory on that level. If there are tree items associated with the 'reloaded'
items they will be deleted first. */
int ScanFromDir(VdtcTreeItemBase *item, const wxFileName &path, int level);
/** Get files for current dir */
void GetFiles(VdtcTreeItemBase *parent, VdtcTreeItemBaseArray &items, const wxFileName &path);
/** get dirs in current dir */
void GetDirectories(VdtcTreeItemBase *parent, VdtcTreeItemBaseArray &items, const wxFileName &path);
void AppendPathRecursively(VdtcTreeItemBase *b, wxFileName &dir, bool useRoot = true);
/** Adds items on this level to the parent dir associated wxTreeCtrl item */
void AddItemsToTreeCtrl(VdtcTreeItemBase *item, VdtcTreeItemBaseArray &items);
/** Sorts items with qsort algorithm */
void SortItems(VdtcTreeItemBaseArray &items, int left, int right);
/** Built in swap algoritm */
void SwapItem(VdtcTreeItemBaseArray &items, int a, int b);
// -- event handlers --
void OnExpanding(wxTreeEvent &event);
protected:
/** This method can be used in the method OnAssignIcons. It returns a pointer to a newly created bitmap
holding the default icon image for a root node. NOTE: When this bitmap is assigned to the icon list,
don't forget to delete it! */
wxBitmap *CreateRootBitmap();
/** This method can be used in the method OnAssignIcons. It returns a pointer to a newly created bitmap
holding the default icon image for a folder node. NOTE: When this bitmap is assigned to the icon list,
don't forget to delete it! */
wxBitmap *CreateFolderBitmap();
/** This method can be used in the method OnAssignIcons. It returns a pointer to a newly created bitmap
holding the default icon image for a file node. NOTE: When this bitmap is assigned to the icon list,
don't forget to delete it! */
wxBitmap *CreateFileBitmap();
/** Inherited virtual function for SortChildren */
int OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2);
public:
/** Default constructor of this control. It is similar to the wxTreeCtrl */
wxVirtualDirTreeCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = wxTR_HAS_BUTTONS | wxTR_FULL_ROW_HIGHLIGHT,
const wxValidator& validator = wxDefaultValidator,
const wxString& name = _T("wxVirtualDirTreeCtrl"));
virtual ~wxVirtualDirTreeCtrl();
/** Returns the extra flags currently set set for wxVirtualDirTreeCtrl.
\sa SetRootPath */
int GetExtraFlags() const {
return _flags;
};
/** Sets the root path of the wxVirtualDirTreeCtrl. This will reset the view and restart the
process of notification, and all events that need to be called. Returns false when this
root path does not lead to any valid filesystem or directory. Set extra flags for
wxVirtualDirTreeCtrl when needed. The following flags are possible
- wxVDTC_DEFAULT
- wxVDTC_RELOAD_ALL
- wxVDTC_NO_EXPAND
- wxVDTC_SHOW_BUSYDLG
- wxVDTC_NO_SORT
- wxVDTC_NO_FILES */
bool SetRootPath(const wxString &root, int flags = wxVDTC_DEFAULT);
/** Resets the extensions to "*.*" as default (or "*" under linux). The extension will be used
upon next reload of the directory tree. In between extensions can be changed but will have
no effect upon the directory scanning mechanism until the next SetRootPath */
void ResetExtensions() {
_extensions.Clear();
_extensions.Add(VDTC_DIR_FILESPEC);
};
/** Returns the relative path of the item with the given wxTreeItemId. This doesn't include the
root node. This can be used in ExpandToPath(). A check is made if the object belonging to this
wxTreeItemId is of the type directory or file. In both cases the relative path (plus filename if
it is a file) is returned. When the object pointed out by wxTreeItemId is of the type root, an
empty wxFileName is returned. Be warned, these functions can take some time because the whole tree
structure is iterated from the top node down to the root */
wxFileName GetRelativePath(const wxTreeItemId &id);
/** Return full path of given node. This can also include the name of the file. This will be returned as
a wxFileName (with path and possible name) to be used further. Be warned, these functions can take some time because the whole tree
structure is iterated from the top node down to the root. */
wxFileName GetFullPath(const wxTreeItemId &id);
/** Returns TRUE when the item pointed out by wxTreeItemId is a root node internally, this means the
assigned VdtcTreeItemBase class is of type VDTC_TI_ROOT.
\sa VdtcTreeItemBase::IsRoot */
bool IsRootNode(const wxTreeItemId &id);
/** Returns TRUE when the item pointed out by wxTreeItemId is a directory node internally, this means the
assigned VdtcTreeItemBase class is of type VDTC_TI_DIR. For these types of nodes you can use i.e.
GetRelativePath() or GetFullPath() to retrieve the directory.
\sa VdtcTreeItemBase::IsDir, GetRelativePath, GetFullPath */
bool IsDirNode(const wxTreeItemId &id);
/** Returns TRUE when the item pointed out by wxTreeItemId is a file node internally, this means the
assigned VdtcTreeItemBase class is of type VDTC_TI_DIR. For these types of nodes you can use i.e.
GetRelativePath() or GetFullPath() to retrieve the directory plus filename.
\sa VdtcTreeItemBase::IsFile, GetRelativePath, GetFullPath */
bool IsFileNode(const wxTreeItemId &id);
/** Expands from root, to the given path. Every path in the wxFileName is looked up and expanded. When
a path section is not found, this method aborts and returns a wxTreeItemId with value 0. When it succeeds
the wxTreeItemId is returned of the last tree item that was expanded.
<b>A special note:</b> Don't include the root path of the current tree in the filename. This part of the path
is not used to scan. Use GetRelativePath to get the path up until a specific node. This method is useful
to expand earlier paths after restoring the window state.
\sa GetRelativePath */
wxTreeItemId ExpandToPath(const wxFileName &path);
/** Adds a file item. Be aware that this call does not add it to the wxTreeCtrl. This only creates an instance
of a VtdcTreeItemBase file node. The handler OnCreateTreeItem is called to allow the proper initialisation
of every newly created instance of the (inherited) VdtcTreeItemBase class. */
VdtcTreeItemBase *AddFileItem(const wxString &name);
/** Adds a directory item. Be aware that this call does not add it to the wxTreeCtrl. This only creates an instance
of a VtdcTreeItemBase directory node. The handler OnCreateTreeItem is called to allow the proper initialisation
of every newly created instance of the (inherited) VdtcTreeItemBase class. */
VdtcTreeItemBase *AddDirItem(const wxString &name);
/** Returns parent of the passed VdtcItemBase object. It will fetch the wxTreeItemId of this parent,
and return the VdtcTreeItemBase parent associated with it. If the associated item is nil, there is no
parent, this is most likely the root else an assertion failure occurs */
VdtcTreeItemBase *GetParent(VdtcTreeItemBase *item) const {
wxCHECK(item, 0);
wxTreeItemId p = GetItemParent(item->GetId());
if (! p.IsOk()) return NULL;
return (VdtcTreeItemBase *)GetItemData(p);
};
// --- handlers ---
/** This handler is called when the SetRootPath function is called. This call causes a re-initialisation of
the wxVirtualDirTreeCtrl. It can be useful to initialise the class that derived this class as well. The
root is passed as parameter to inform which root is going to be set. NOTE: When this method is called,
the following criteria is true:
- The tree is completely empty
- The path parameter is valid. When it's not valid this call is not made */
void OnSetRootPath(const wxString &root);
/** This virtual handler is used to allow the developer to assign custom icons to the
image list. Override this method to assign your own icons to the wxTreeCtrl. The default method
will assign a root bitmap, a folder bitmap and a file bitmap. The icons assigned can be
refered to in the OnFileName and OnDirectory handlers, to specify what icon should be used.
The default images can be used by these constants:
- VDTC_ICON_ROOT
- VDTC_ICON_DIR
- VDTC_ICON_FILE
The icon list contains icons which are 16x16 in size.
*/
virtual void OnAssignIcons(wxImageList &icons);
/** This handler provides must provide a VdtcTreeItemBase* instance to be used upon creation. If you
override this handler, you can return your own class, which might embed more information.
The type tells you what kind of element is created, a root item (VDTC_TI_ROOT), a dir item (VDTC_TI_DIR)
or a file item (VDTC_TI_FILE). Dependent upon the type you can return a different class based upon
VdtcTreeItemBase.
For example, this is the standard implementation:
\code
return new VdtcTreeItemBase(type, name);
\endcode
You could derive the wxVirtualDirTreeCtrl and VdtcTreeItemBase object and make this:
\code
switch(type)
{
case VDTC_TI_ROOT:
return new MyRootItem(type, name); // MyRootItem = class derived VdtcTreeItemBase
case VDTC_TI_DIR:
return new MyDirItem(type, name); // MyDirItem = class derived VdtcTreeItemBase
case VDTC_TI_FILE:
return new MyFileItem(type, name); // MyFileItem = class derived VdtcTreeItemBase
}
return 0;
\endcode
\sa VdtcTreeItemBase
*/
virtual VdtcTreeItemBase *OnCreateTreeItem(int type, const wxString &name);
/** This handler is called before the VdtcTreeItemBase item is added to the root. This will be the first item to be added
before all else is added.
If for some reason this root is denied to be added, return FALSE. If it may be added, return TRUE. If false is returned
then no other items are created, and the SetRootPath() function returns with FALSE notifying the caller that something
went wrong.
\sa VdtcTreeItemBase
*/
virtual bool OnAddRoot(VdtcTreeItemBase &item, const wxFileName &name);
/** This handler is called before a file VdtcTreeItemBase item is added to the tree. For every file added in the tree this
handler is called. It allows you to change the name or caption of the item, and also gain more information
or change the contents of the associated VdtcTreeItemBase class. The wxFileName contains the full path
of the item to be added, so it can be easily inspected, and tested for specific extensions, parts of the
name and what else.
If for some reason this item is denied to be added, return FALSE. If it may be added, return TRUE.
*/
virtual bool OnAddFile(VdtcTreeItemBase &item, const wxFileName &name);
/** This handler is called before a directory item is added to the tree. For every dir added in the tree this
handler is called. It allows you to change the name of the item or the caption, and also gain more information of the
directory, and check if specific files are present. The wxFileName contains the full path of the directory
to be added, so it can be easily inspected, and tested for specific criteria, parts of the name and what else.
If for some reason this item is denied to be added, return FALSE. If it may be added, return TRUE.
*/
virtual bool OnAddDirectory(VdtcTreeItemBase &item, const wxFileName &name);
/** This handler is called before the directory specified by 'path' is scanned. You can veto this scan by
returning 'false'. This way the scanning of all files and directories in this path is skipped. After this
handler, subsequent calls to OnAddFile, OnAddDirectory will be made for every file and directory
encountered in this level to be scanned. NOTE: When this scan is veto'd there will be no call
to OnDirectoryScanEnd because there was no scan. Also OnAddedItems is not called */
virtual bool OnDirectoryScanBegin(const wxFileName &path);
/** This handler is called when all files and all directories are scanned in the current dir and iterated in
the array passed to this method. Before the sorting algorithm is initiated, the developer is allowed to
take one last look at all the files, maybe delete some or act upon other criteria. The items parameter
contains the pointer array of all the items that are in the list, and the path parameter contains the
current path investigated. NOTE: If you want to delete an item from the array, delete it with delete
operator and remove the pointer from the list. */
virtual void OnDirectoryScanEnd(VdtcTreeItemBaseArray &items, const wxFileName &path);
/** This handler is called the very moment after all items are added to the tree control. The parent parameter
contains the tree node to which the items are added. They are already sorted and ready. E.g. when you don't
want to use the internal sort algoritm this is a nice place to call SortChildren on the parent node */
virtual void OnAddedItems(const wxTreeItemId &parent);
/** This handler is called during the sorting of the tree control items. Return < 0 when a < b, > 0 when a > b
and 0 when a == b.
*/
virtual int OnCompareItems(const VdtcTreeItemBase *a, const VdtcTreeItemBase *b);
private:
// WDR: member variable declarations for wxVirtualDirTreeCtrl
private:
// WDR: handler declarations for wxVirtualDirTreeCtrl
private:
DECLARE_EVENT_TABLE()
};
#endif

View File

@ -0,0 +1,50 @@
// Just another boring app that creates a ColourTester window
#include "stdafx.h"
#include "ColourTester/ColourTester.h"
#include "Datafile.h"
#include "wx/file.h"
#include "wx/config.h"
#include "wx/generic/colrdlgg.h"
#include "wx/generic/filedlgg.h"
#include "wx/generic/dirctrlg.h"
#include "wx/generic/dirdlgg.h"
class MyApp: public wxApp
{
bool OnInit()
{
// Initialise the global config file
wxConfigBase::Set(new wxConfig(_T("Atlas Editor"), _T("Wildfire Games")));
// Assume that the .exe is located in .../binaries/system. (We can't
// just use the cwd, since that isn't correct when being executed by
// dragging-and-dropping onto the program in Explorer.)
Datafile::SetSystemDirectory(argv[0]);
// Display the main program window
wxFrame *frame = new ColourTester(NULL);
frame->Show();
SetTopWindow(frame);
/*
// One argument => argv[1] is a filename to open
if (argc > 1)
{
wxChar* filename = argv[1];
if (wxFile::Exists(filename))
frame->OpenFile(filename);
else
wxLogError(_("Cannot find file '%s'"), filename);
}
*/
return true;
}
};
IMPLEMENT_APP(MyApp)

View File

@ -20,6 +20,7 @@
#include "wx/file.h"
#include "wx/colordlg.h"
#include "wx/regex.h"
#include "wx/image.h"
#include <vector>
#include <string>

View File

@ -1,11 +1,11 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "textureconv", "textureconv.vcproj", "{FFB317CC-4B72-4CA5-9CB8-86A8A0E8382E}"
ProjectSection(ProjectDependencies) = postProject
{CF979F49-FDC6-4A13-A6E7-C481DB98D856} = {CF979F49-FDC6-4A13-A6E7-C481DB98D856}
{76BBC723-9716-451F-92D9-A7B65F3BA85F} = {76BBC723-9716-451F-92D9-A7B65F3BA85F}
{984C31F1-11EB-4D44-ACF4-B3F573E1F08E} = {984C31F1-11EB-4D44-ACF4-B3F573E1F08E}
EndProjectSection
EndProject
Project("{EAF909A5-FA59-4C3D-9431-0FCC20D5BCF9}") = "IL", "..\..\..\libraries\devil\src\src-IL\msvc\il.icproj", "{CF979F49-FDC6-4A13-A6E7-C481DB98D856}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "IL", "..\..\..\libraries\devil\src\src-IL\msvc\il.vcproj", "{76BBC723-9716-451F-92D9-A7B65F3BA85F}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
@ -23,12 +23,10 @@ Global
{FFB317CC-4B72-4CA5-9CB8-86A8A0E8382E}.Debug.Build.0 = Debug|Win32
{FFB317CC-4B72-4CA5-9CB8-86A8A0E8382E}.Release.ActiveCfg = Release|Win32
{FFB317CC-4B72-4CA5-9CB8-86A8A0E8382E}.Release.Build.0 = Release|Win32
{CF979F49-FDC6-4A13-A6E7-C481DB98D856}.Debug.ActiveCfg = Debug|Win32
{CF979F49-FDC6-4A13-A6E7-C481DB98D856}.Debug.Build.0 = Debug|Win32
{CF979F49-FDC6-4A13-A6E7-C481DB98D856}.Release.ActiveCfg = Release|Win32
{CF979F49-FDC6-4A13-A6E7-C481DB98D856}.Release.Build.0 = Release|Win32
{BAC3571A-7AD2-40BD-B920-88443D73F84F}.Debug.ActiveCfg = Debug|Win32
{BAC3571A-7AD2-40BD-B920-88443D73F84F}.Release.ActiveCfg = Release|Win32
{76BBC723-9716-451F-92D9-A7B65F3BA85F}.Debug.ActiveCfg = Debug|Win32
{76BBC723-9716-451F-92D9-A7B65F3BA85F}.Debug.Build.0 = Debug|Win32
{76BBC723-9716-451F-92D9-A7B65F3BA85F}.Release.ActiveCfg = Release|Win32
{76BBC723-9716-451F-92D9-A7B65F3BA85F}.Release.Build.0 = Release|Win32
{984C31F1-11EB-4D44-ACF4-B3F573E1F08E}.Debug.ActiveCfg = Debug|Win32
{984C31F1-11EB-4D44-ACF4-B3F573E1F08E}.Debug.Build.0 = Debug|Win32
{984C31F1-11EB-4D44-ACF4-B3F573E1F08E}.Release.ActiveCfg = Release|Win32

View File

@ -15,7 +15,7 @@
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
CharacterSet="1">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
@ -23,7 +23,7 @@
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="0"
RuntimeLibrary="5"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
@ -32,7 +32,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libcd.lib DevIL_DBG.lib DevILU_DBG.lib"
AdditionalDependencies="DevIL_DBG.lib DevILU_DBG.lib"
OutputFile="$(OutDir)/textureconv.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;..\..\..\libraries\devil\src\lib&quot;"
@ -67,12 +67,12 @@
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
CharacterSet="1">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\libraries\devil\src\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
RuntimeLibrary="2"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
@ -82,7 +82,7 @@
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libc.lib DevIL.lib DevILU.lib"
AdditionalDependencies="DevIL.lib DevILU.lib"
OutputFile="$(OutDir)/textureconv.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="&quot;..\..\..\libraries\devil\src\lib&quot;;&quot;e:\icc81\compiler80\ia32\lib&quot;"