summaryrefslogtreecommitdiff
path: root/win/texdlg.cpp
blob: 1bafd029012844cb98d78837370b105654e138d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// texdlg.cpp : implementation file
//

#include "stdafx.h"
#include "leocad.h"
#include "texdlg.h"
#include "library.h"
#include "project.h"
#include "globals.h"
#include "texture.h"
#include "lc_application.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTexturesDlg dialog


CTexturesDlg::CTexturesDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTexturesDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTexturesDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CTexturesDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTexturesDlg)
	DDX_Control(pDX, ID_LIBTEX_LIST, m_List);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTexturesDlg, CDialog)
	//{{AFX_MSG_MAP(CTexturesDlg)
	ON_BN_CLICKED(ID_LIBTEX_ADD, OnLibtexAdd)
	ON_BN_CLICKED(ID_LIBTEX_REMOVE, OnLibtexRemove)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTexturesDlg message handlers

BOOL CTexturesDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	UpdateList();
	
	return TRUE;
}

void CTexturesDlg::OnOK() 
{
	CDialog::OnOK();
}

void CTexturesDlg::OnLibtexAdd() 
{
	CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		"All Image Files|*.bmp;*.gif;*.jpg;*.png|JPEG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|BMP Files (*.bmp)|*.bmp|PNG Files (*.png)|*.png|All Files (*.*)|*.*||", this);

	if (dlg.DoModal() == IDOK)
	{
		lcGetPiecesLibrary()->ImportTexture(dlg.GetPathName());
		UpdateList();
	}
}

void CTexturesDlg::OnLibtexRemove() 
{
	int i, selected = 0;

	for (i = 0; i < m_List.GetCount(); i++)
		if (m_List.GetSel(i))
			selected++;

	// Nothing to be done
	if (selected == 0)
		return;

	char** names = (char**)malloc(selected*sizeof(char**));

	for (selected = 0, i = 0; i < m_List.GetCount(); i++)
	{
		if (m_List.GetSel(i))
		{
			names[selected] = (char*)m_List.GetItemDataPtr (i);;
			selected++;
		}
	}

	lcGetPiecesLibrary()->DeleteTextures(names, selected);

	free (names);

	UpdateList();
}

void CTexturesDlg::UpdateList()
{
	PiecesLibrary *pLib = lcGetPiecesLibrary();

	m_List.ResetContent();

	for (int i = 0; i < pLib->GetTextureCount(); i++)
	{
		int index = m_List.AddString (pLib->GetTexture(i)->m_strName);
		m_List.SetItemDataPtr(index, pLib->GetTexture(i)->m_strName);
	}
}