1 | #include "OgreExport.h" |
---|
2 | #include "resource.h" |
---|
3 | |
---|
4 | static OgreMaxExport_SkeletalAnimation* sInst; |
---|
5 | |
---|
6 | void OgreMaxExport_SkeletalAnimation::onInitDialog(HWND hDlg) { |
---|
7 | OgreMaxExport_TabPaneHandler::onInitDialog(hDlg); |
---|
8 | |
---|
9 | // set up animation listbox |
---|
10 | int frameStart = m_i->GetAnimRange().Start(); |
---|
11 | int frameEnd = m_i->GetAnimRange().End(); |
---|
12 | |
---|
13 | HWND anims = GetDlgItem(m_hDlg, IDC_LIST_ANIMATIONS); |
---|
14 | |
---|
15 | Rect r; |
---|
16 | GetWindowRect(anims, &r); |
---|
17 | |
---|
18 | LVCOLUMN lvc; |
---|
19 | ZeroMemory(&lvc, sizeof(LVCOLUMN)); |
---|
20 | lvc.mask = LVCF_TEXT | LVCF_WIDTH; |
---|
21 | lvc.cx = r.w() * 0.6; |
---|
22 | lvc.pszText = "Animation"; |
---|
23 | ListView_InsertColumn(anims, 0, &lvc); |
---|
24 | lvc.cx = r.w() * 0.2; |
---|
25 | lvc.pszText = "Begin"; |
---|
26 | ListView_InsertColumn(anims, 1, &lvc); |
---|
27 | lvc.pszText = "End"; |
---|
28 | ListView_InsertColumn(anims, 2, &lvc); |
---|
29 | |
---|
30 | // add a spanning entry to the animation list as a default |
---|
31 | LVITEM lvi; |
---|
32 | char buf[32]; |
---|
33 | ZeroMemory(&lvi, sizeof(LVITEM)); |
---|
34 | |
---|
35 | lvi.mask = LVIF_TEXT; |
---|
36 | lvi.pszText = "Animation"; |
---|
37 | lvi.iItem = 10000; |
---|
38 | int idx = ListView_InsertItem(anims, &lvi); |
---|
39 | |
---|
40 | sprintf(buf, "%d", frameStart / GetTicksPerFrame()); |
---|
41 | lvi.iItem = idx; |
---|
42 | lvi.iSubItem = 1; |
---|
43 | lvi.pszText = buf; |
---|
44 | ListView_SetItem(anims, &lvi); |
---|
45 | |
---|
46 | sprintf(buf, "%d", frameEnd / GetTicksPerFrame()); |
---|
47 | lvi.iSubItem = 2; |
---|
48 | lvi.pszText = buf; |
---|
49 | ListView_SetItem(anims, &lvi); |
---|
50 | |
---|
51 | // populate the frame range info box |
---|
52 | sprintf(buf, "%d to %d", frameStart / GetTicksPerFrame(), frameEnd / GetTicksPerFrame()); |
---|
53 | SendMessage(GetDlgItem(m_hDlg, IDC_TXT_FRAME_RANGE), WM_SETTEXT, 0, (LPARAM)buf); |
---|
54 | SendMessage(GetDlgItem(m_hDlg, IDC_TXT_FPS), WM_SETTEXT, 0, (LPARAM)_T("1.0")); |
---|
55 | } |
---|
56 | |
---|
57 | void OgreMaxExport_SkeletalAnimation::onDestroy() { |
---|
58 | update(); |
---|
59 | } |
---|
60 | |
---|
61 | // read the contents from the dialog controls |
---|
62 | void OgreMaxExport_SkeletalAnimation::update() { |
---|
63 | |
---|
64 | } |
---|
65 | |
---|
66 | void OgreMaxExport_SkeletalAnimation::onAddAnimation() { |
---|
67 | addAnimation(); |
---|
68 | } |
---|
69 | |
---|
70 | void OgreMaxExport_SkeletalAnimation::onDeleteAnimation() { |
---|
71 | deleteAnimation(); |
---|
72 | } |
---|
73 | |
---|
74 | void OgreMaxExport_SkeletalAnimation::addAnimation() { |
---|
75 | char buf[256]; |
---|
76 | int start, end; |
---|
77 | HWND anims = GetDlgItem(m_hDlg, IDC_LIST_ANIMATIONS); |
---|
78 | |
---|
79 | SendMessage(GetDlgItem(m_hDlg, IDC_TXT_FPS), WM_GETTEXT, 256, (LPARAM)buf); |
---|
80 | float fps = atof(buf); |
---|
81 | |
---|
82 | if (fps <= 0.0) { |
---|
83 | MessageBox(NULL, "FPS must be >= 0.0", "Invalid Entry", MB_ICONEXCLAMATION); |
---|
84 | return; |
---|
85 | } |
---|
86 | |
---|
87 | int minAnimTime = m_i->GetAnimRange().Start() / GetTicksPerFrame(); |
---|
88 | int maxAnimTime = m_i->GetAnimRange().End() / GetTicksPerFrame(); |
---|
89 | |
---|
90 | // get animation start and end times |
---|
91 | SendMessage(GetDlgItem(m_hDlg, IDC_TXT_ANIM_START), WM_GETTEXT, 256, (LPARAM)buf); |
---|
92 | start = atoi(buf); |
---|
93 | |
---|
94 | if (start < minAnimTime) { |
---|
95 | sprintf(buf, "Start time must be >= %d", start); |
---|
96 | MessageBox(NULL, buf, "Invalid Entry", MB_ICONEXCLAMATION); |
---|
97 | return; |
---|
98 | } |
---|
99 | |
---|
100 | SendMessage(GetDlgItem(m_hDlg, IDC_TXT_ANIM_END), WM_GETTEXT, 256, (LPARAM)buf); |
---|
101 | end = atoi(buf); |
---|
102 | |
---|
103 | if (end > maxAnimTime) { |
---|
104 | sprintf(buf, "End time must be <= %d", end); |
---|
105 | MessageBox(NULL, buf, "Invalid Entry", MB_ICONEXCLAMATION); |
---|
106 | return; |
---|
107 | } |
---|
108 | |
---|
109 | // get animation name |
---|
110 | SendMessage(GetDlgItem(m_hDlg, IDC_TXT_ANIMATION_NAME), WM_GETTEXT, 256, (LPARAM)buf); |
---|
111 | std::string name(buf); |
---|
112 | |
---|
113 | if (name.length() == 0) { |
---|
114 | MessageBox(NULL, "Animation name must not be empty", "Invalid Entry", MB_ICONEXCLAMATION); |
---|
115 | return; |
---|
116 | } |
---|
117 | |
---|
118 | // if, after all that, we have valid data, stick it in the listview |
---|
119 | LVITEM lvi; |
---|
120 | ZeroMemory(&lvi, sizeof(LVITEM)); |
---|
121 | |
---|
122 | lvi.mask = LVIF_TEXT; |
---|
123 | lvi.pszText = buf; |
---|
124 | lvi.iItem = 10000; |
---|
125 | int idx = ListView_InsertItem(anims, &lvi); |
---|
126 | |
---|
127 | lvi.iItem = idx; |
---|
128 | lvi.iSubItem = 1; |
---|
129 | sprintf(buf, "%d", start); |
---|
130 | lvi.pszText = buf; |
---|
131 | ListView_SetItem(anims, &lvi); |
---|
132 | lvi.iSubItem = 2; |
---|
133 | sprintf(buf, "%d", end); |
---|
134 | lvi.pszText = buf; |
---|
135 | ListView_SetItem(anims, &lvi); |
---|
136 | |
---|
137 | // Finally, clear out the entry controls |
---|
138 | SetWindowText(GetDlgItem(m_hDlg, IDC_TXT_ANIMATION_NAME), ""); |
---|
139 | SetWindowText(GetDlgItem(m_hDlg, IDC_TXT_ANIM_START), ""); |
---|
140 | SetWindowText(GetDlgItem(m_hDlg, IDC_TXT_ANIM_END), ""); |
---|
141 | } |
---|
142 | |
---|
143 | void OgreMaxExport_SkeletalAnimation::deleteAnimation() { |
---|
144 | |
---|
145 | HWND anims = GetDlgItem(m_hDlg, IDC_LIST_ANIMATIONS); |
---|
146 | |
---|
147 | // delete selected animation(s) from the listview |
---|
148 | int idx; |
---|
149 | while ((idx=ListView_GetNextItem(anims, -1, LVNI_SELECTED)) != -1) |
---|
150 | ListView_DeleteItem(anims, idx); |
---|
151 | } |
---|
152 | |
---|
153 | // for the sake of sanity, keep the dlgproc and the handler class implementation here in the same source file |
---|
154 | INT_PTR CALLBACK SkeletalAnimationTabDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { |
---|
155 | |
---|
156 | switch(message) { |
---|
157 | case WM_INITDIALOG: |
---|
158 | sInst = (OgreMaxExport_SkeletalAnimation*) lParam; |
---|
159 | |
---|
160 | sInst->onInitDialog(hDlg); |
---|
161 | SetWindowPos(hDlg, HWND_TOP, 10, 40, 0, 0, SWP_NOSIZE); |
---|
162 | ShowWindow(hDlg, SW_SHOW); |
---|
163 | break; |
---|
164 | |
---|
165 | case WM_COMMAND: |
---|
166 | switch(LOWORD(wParam)) { |
---|
167 | case IDC_CMD_DELETE_ANIMATION: |
---|
168 | sInst->onDeleteAnimation(); |
---|
169 | break; |
---|
170 | case IDC_CMD_ADD_ANIMATION: |
---|
171 | sInst->onAddAnimation(); |
---|
172 | break; |
---|
173 | } |
---|
174 | break; |
---|
175 | |
---|
176 | case WM_NOTIFY: |
---|
177 | break; |
---|
178 | |
---|
179 | case WM_DESTROY: |
---|
180 | sInst->onDestroy(); |
---|
181 | break; |
---|
182 | } |
---|
183 | return FALSE; |
---|
184 | } |
---|