summaryrefslogtreecommitdiff
path: root/common/library.h
blob: 464627fad3f918c70cd7e6e88fedc835f141f27c (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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef _LIBRARY_H_
#define _LIBRARY_H_

typedef enum {
  LC_LIBDLG_FILE_RESET,
  LC_LIBDLG_FILE_OPEN,
  LC_LIBDLG_FILE_SAVE,
  LC_LIBDLG_FILE_SAVEAS,
  LC_LIBDLG_FILE_PRINTCATALOG,
  LC_LIBDLG_FILE_MERGEUPDATE,
  LC_LIBDLG_FILE_IMPORTPIECE,
  LC_LIBDLG_FILE_RETURN,
  LC_LIBDLG_FILE_CANCEL,
  LC_LIBDLG_GROUP_INSERT,
  LC_LIBDLG_GROUP_DELETE,
  LC_LIBDLG_GROUP_EDIT,
  LC_LIBDLG_GROUP_MOVEUP,
  LC_LIBDLG_GROUP_MOVEDOWN,
  LC_LIBDLG_PIECE_NEW,
  LC_LIBDLG_PIECE_EDIT,
  LC_LIBDLG_PIECE_DELETE
} LC_LIBDLG_COMMANDS;

class PieceInfo;
class LibraryDialog;

typedef struct
{
  PieceInfo* info;
  unsigned long current_groups;
  unsigned long default_groups;
} LC_LIBDLG_PIECEINFO;

#define LC_LIBDLG_MAXGROUPS 32
#define LC_LIBDLG_MAXNAME   32

typedef void (*PFNLIBDLGUPDATELISTFUNC) (LC_LIBDLG_PIECEINFO *piece_info, int count, int group, void *data);
typedef void (*PFNLIBDLGUPDATETREEFUNC) (int num_groups, char str_groups[][LC_LIBDLG_MAXNAME+1], void *data);

class LibraryDialog
{
 public:
  LibraryDialog ();
  virtual ~LibraryDialog ();

  void HandleCommand (int id);
  bool DoSave (bool bAskName);
  bool Initialize ();

  void SetListFunc (PFNLIBDLGUPDATELISTFUNC func, void *data)
    {
      m_pUpdateListFunc = func;
      m_pUpdateListData = data;
    }

  void SetTreeFunc (PFNLIBDLGUPDATETREEFUNC func, void *data)
    {
      m_pUpdateTreeFunc = func;
      m_pUpdateTreeData = data;
    }

  void UpdateList ()
    {
      m_pUpdateListFunc (m_pPieces, m_nPieces, m_nCurrentGroup, m_pUpdateListData);
    }

  void UpdateTree ()
    {
      m_pUpdateTreeFunc (m_nGroups, m_strGroups, m_pUpdateTreeData);
    }

  void SetCurrentGroup (unsigned long group)
    {
      m_nCurrentGroup = group;
      UpdateList ();
    }

 protected:
  void *m_pUpdateListData;
  void *m_pUpdateTreeData;
  PFNLIBDLGUPDATELISTFUNC m_pUpdateListFunc;
  PFNLIBDLGUPDATETREEFUNC m_pUpdateTreeFunc;

  int m_nPieces;
  LC_LIBDLG_PIECEINFO* m_pPieces;

  unsigned char m_nGroups;
  char m_strGroups[LC_LIBDLG_MAXGROUPS][LC_LIBDLG_MAXNAME+1];
  int m_nCurrentGroup;

  bool m_bModified;
  bool m_bReload;
  char m_strFile[LC_MAXPATH];
};

typedef struct connection_s
{
	unsigned char type;
	float pos[3];
	float up[3];
	connection_s* next;
} connection_t;

typedef struct group_s
{
	connection_t* connections[5];
	void* drawinfo;
	unsigned long infosize;
	group_s* next;
} group_t;

typedef struct lineinfo_s
{
	unsigned char type;
	unsigned char color;
	float points[12];
	lineinfo_s* next;
} lineinfo_t;

typedef struct texture_s
{
	float points[20];
	unsigned char color;
	char name[9];
	texture_s* next;
} texture_t;

typedef struct
{
	float* verts;
	unsigned int verts_count;
	connection_t* connections;
	group_t* groups;
	texture_t* textures;
	char name[9];
	char description[65];
} LC_LDRAW_PIECE;

bool ReadLDrawPiece(const char* filename, LC_LDRAW_PIECE* piece);
bool SaveLDrawPiece(LC_LDRAW_PIECE* piece);
void FreeLDrawPiece(LC_LDRAW_PIECE* piece);
bool DeletePiece(char** names, int numpieces);
bool LoadUpdate(const char* update);

#endif // _LIBRARY_H_