1 /*
2 * SceneDialog.cpp
3 *
4 * Copyright (C) 2003, 2019 J. "MUFTI" Scheurich
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program (see the file "COPYING" for details); if
18 * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 * Cambridge, MA 02139, USA.
20 */
21
22 #include "SceneDialog.h"
23 #include "resource.h"
24 #include "swt.h"
25 #include "NodeVrmlScene.h"
26
SceneDialog(SWND parent,Node * node,bool add,int sceneNumber,NodeVrmlCut * vrmlCut)27 SceneDialog::SceneDialog(SWND parent, Node* node, bool add, int sceneNumber,
28 NodeVrmlCut *vrmlCut)
29 : Dialog(parent, IDD_SCENES_MANAGE)
30 {
31 m_node = node;
32 m_add = add;
33 m_vrmlCut = vrmlCut;
34 m_sceneNumber = sceneNumber;
35 m_oldSceneNumber = sceneNumber;
36 LoadData();
37 }
38
39 void
OnCommand(void * vid)40 SceneDialog::OnCommand(void *vid)
41 {
42 int id = swFromPtr(vid);
43 if (id == IDOK) {
44 SaveData();
45 if (Validate()) {
46 swEndDialog(IDOK);
47 }
48 } else if (id == IDCANCEL) {
49 swEndDialog(IDCANCEL);
50 } else if (id == IDC_SCENES_FIRST) {
51 LoadData();
52 } else if (id == IDC_SCENES_LAST) {
53 LoadData();
54 } else if (id == IDC_SCENE_NUMBER) {
55 loadComboxData();
56 LoadData();
57 }
58 }
59
60 bool
Validate()61 SceneDialog::Validate()
62 {
63 char buf[256];
64 if (swGetCheck(swGetDialogItem(m_dlg, IDC_SCENES_FIRST)) &&
65 swGetCheck(swGetDialogItem(m_dlg, IDC_SCENES_LAST))) {
66 swLoadString(IDS_SCENES_NUMBER_NOT_FIRST_AND_LAST + swGetLang(), buf,
67 255);
68 TheApp->MessageBox(buf);
69 return false;
70 }
71 swGetText(swGetDialogItem(m_dlg, IDC_SCENES_NUMBER), buf, 255);
72 int sceneNumber = atoi(buf);
73 if ((sceneNumber < 0) || (sceneNumber > m_vrmlCut->scenes()->getSize() - 1)) {
74 swLoadString(IDS_SCENES_NUMBER_NOT_VALID + swGetLang(), buf,
75 255);
76 TheApp->MessageBox(buf);
77 return false;
78 }
79 swGetText(swGetDialogItem(m_dlg, IDC_SCENE_NUMBER), buf, 255);
80 sceneNumber = atoi(buf);
81 if ((sceneNumber < 0) || (sceneNumber > m_vrmlCut->scenes()->getSize() - 1)) {
82 swLoadString(IDS_SCENES_NUMBER_NOT_VALID + swGetLang(), buf,
83 255);
84 TheApp->MessageBox(buf);
85 return false;
86 }
87 return true;
88 }
89
90 void
loadComboxData(void)91 SceneDialog::loadComboxData(void)
92 {
93 int number = swComboBoxGetSelection(swGetDialogItem(m_dlg,
94 IDC_SCENE_NUMBER));
95 if (number != 0)
96 m_sceneNumber = number - 1;
97 if (m_sceneNumber > m_vrmlCut->sceneLengths()->getSize() - 1)
98 m_sceneNumber = m_vrmlCut->sceneLengths()->getSize() - 1;
99 }
100
101 void
LoadData()102 SceneDialog::LoadData()
103 {
104 SWND comboNumbers = swGetDialogItem(m_dlg, IDC_SCENE_NUMBER);
105 swComboBoxDeleteAll(comboNumbers);
106
107 swComboBoxAppendItem(comboNumbers, " ");
108
109 char buf[256];
110 for (int i = 0; i < m_vrmlCut->scenes()->getSize(); i++) {
111 snprintf(buf, 256, "%d", i);
112 swComboBoxAppendItem(comboNumbers, buf);
113 }
114 swLoadString(IDS_SCENES_LAST, buf, 255);
115 swComboBoxAppendItem(comboNumbers, buf);
116
117 snprintf(buf, 256, "%d", m_sceneNumber);
118 swSetText(swGetDialogItem(m_dlg, IDC_SCENES_NUMBER), buf);
119
120 snprintf(buf, 256, "%lf", getSceneLength());
121 swSetText(swGetDialogItem(m_dlg, IDC_SCENES_LENGTH), buf);
122
123 snprintf(buf, 256, "%lf", getSceneDelay());
124 swSetText(swGetDialogItem(m_dlg, IDC_SCENES_DELAY), buf);
125
126 snprintf(buf, 256, "%lf", TheApp->getDefaultSceneLength());
127 swSetText(swGetDialogItem(m_dlg, IDC_DEFAULT_SCENE_LENGTH), buf);
128 }
129
130 void
SaveData()131 SceneDialog::SaveData()
132 {
133 char buf[256];
134
135 m_sceneNumber = swComboBoxGetSelection(
136 swGetDialogItem(m_dlg, IDC_SCENE_NUMBER)) - 1;
137 if (m_sceneNumber == -1) {
138 swGetText(swGetDialogItem(m_dlg, IDC_SCENES_NUMBER), buf, 255);
139 m_sceneNumber = atoi(buf);
140 }
141 if (swGetCheck(swGetDialogItem(m_dlg, IDC_SCENES_FIRST)))
142 m_sceneNumber = 0;
143 if (swGetCheck(swGetDialogItem(m_dlg, IDC_SCENES_LAST)))
144 m_sceneNumber = m_vrmlCut->scenes()->getSize();
145 swGetText(swGetDialogItem(m_dlg, IDC_SCENES_LENGTH), buf, 255);
146 setSceneLength(atof(buf));
147 swGetText(swGetDialogItem(m_dlg, IDC_SCENES_DELAY), buf, 255);
148 setSceneDelay(atof(buf));
149 swGetText(swGetDialogItem(m_dlg, IDC_DEFAULT_SCENE_LENGTH), buf, 255);
150 TheApp->setDefaultSceneLength(atof(buf));
151 }
152
153 double
getSceneLength(void)154 SceneDialog::getSceneLength(void)
155 {
156 return m_vrmlCut->sceneLengths()->getValue(m_oldSceneNumber);
157 }
158
159 void
setSceneLength(double length)160 SceneDialog::setSceneLength(double length)
161 {
162 m_vrmlCut->sceneLengths()->setValue(m_oldSceneNumber, length);
163 }
164
165 double
getSceneDelay(void)166 SceneDialog::getSceneDelay(void)
167 {
168 return m_vrmlCut->sceneDelays()->getValue(m_oldSceneNumber);
169 }
170
171 void
setSceneDelay(double delay)172 SceneDialog::setSceneDelay(double delay)
173 {
174 m_vrmlCut->sceneDelays()->setValue(m_oldSceneNumber, delay);
175 }
176
177
178