~ubuntu-branches/ubuntu/oneiric/soqt/oneiric

« back to all changes in this revision

Viewing changes to build/msvc8/src/Inventor/Qt/nodes/Frame.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2009-03-01 11:41:00 UTC
  • mfrom: (1.1.4 upstream) (5.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090301114100-f4zz3n1oasa52fgk
Tags: 1.4.2~svn20090224-2
* Upload upstream SVN head version containing fixes to build with Coin 3
  (Closes: #515729, #515736, #515742).  Upstream indicated to me that
  SVN is stable enough to release.

* control: Update Standards-Version to 3.8.0; no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**************************************************************************\
2
 
 *
3
 
 *  This file is part of the Coin 3D visualization library.
4
 
 *  Copyright (C) 1998-2005 by Systems in Motion.  All rights reserved.
5
 
 *
6
 
 *  This library is free software; you can redistribute it and/or
7
 
 *  modify it under the terms of the GNU General Public License
8
 
 *  ("GPL") version 2 as published by the Free Software Foundation.
9
 
 *  See the file LICENSE.GPL at the root directory of this source
10
 
 *  distribution for additional information about the GNU GPL.
11
 
 *
12
 
 *  For using Coin with software that can not be combined with the GNU
13
 
 *  GPL, and for taking advantage of the additional benefits of our
14
 
 *  support services, please contact Systems in Motion about acquiring
15
 
 *  a Coin Professional Edition License.
16
 
 *
17
 
 *  See <URL:http://www.coin3d.org/> for more information.
18
 
 *
19
 
 *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
20
 
 *  <URL:http://www.sim.no/>.
21
 
 *
22
 
\**************************************************************************/
23
 
 
24
 
#ifdef HAVE_CONFIG_H
25
 
#include <config.h>
26
 
#endif // HAVE_CONFIG_H
27
 
 
28
 
#include <Inventor/errors/SoDebugError.h>
29
 
#include <Inventor/elements/SoLazyElement.h>
30
 
#include <Inventor/misc/SoState.h>
31
 
#include <Inventor/actions/SoGLRenderAction.h>
32
 
#include <Inventor/nodes/SoSeparator.h>
33
 
#include <Inventor/nodes/SoCoordinate3.h>
34
 
#include <Inventor/nodes/SoMaterial.h>
35
 
#include <Inventor/sensors/SoFieldSensor.h>
36
 
 
37
 
#include <Inventor/Qt/common/gl.h>
38
 
#include <Inventor/Qt/SoAny.h>
39
 
#include <Inventor/Qt/nodes/SoGuiFrame.h>
40
 
#include <assert.h>
41
 
 
42
 
// *************************************************************************
43
 
 
44
 
class Frame {
45
 
public:
46
 
  SoGuiFrame * api;
47
 
 
48
 
  SoCoordinate3 * coords;
49
 
  SoMaterial * light;
50
 
  SoMaterial * shade;
51
 
 
52
 
  SoFieldSensor * size_sensor;
53
 
  SoFieldSensor * width_sensor;
54
 
  static void size_updated_cb(void * closure, SoSensor * sensor);
55
 
 
56
 
  SoFieldSensor * design_sensor;
57
 
  static void design_updated_cb(void * closure, SoSensor * sensor);
58
 
  SoFieldSensor * complement_sensor;
59
 
 
60
 
  static const char * scene[];
61
 
};
62
 
 
63
 
// *************************************************************************
64
 
 
65
 
#define PRIVATE(obj) ((Frame *)obj->internals)
66
 
 
67
 
void
68
 
SoGuiFrame::initClass(void)
69
 
{
70
 
  SO_KIT_INIT_CLASS(SoGuiFrame, SoBaseKit, "BaseKit");
71
 
}
72
 
 
73
 
SO_KIT_SOURCE(SoGuiFrame);
74
 
 
75
 
SoGuiFrame::SoGuiFrame(void)
76
 
{
77
 
  this->internals = new Frame;
78
 
  PRIVATE(this)->api = this;
79
 
 
80
 
  SO_KIT_CONSTRUCTOR(SoGuiFrame);
81
 
 
82
 
  SO_KIT_ADD_FIELD(size, (SbVec3f(0.0f, 0.0f, 0.0f)));
83
 
  SO_KIT_ADD_FIELD(design, (SoGuiFrame::BLACK));
84
 
  SO_KIT_ADD_FIELD(width, (1.0f));
85
 
  SO_KIT_ADD_FIELD(complement, (FALSE));
86
 
 
87
 
  SO_KIT_DEFINE_ENUM_VALUE(FrameDesign, BLACK);
88
 
  SO_KIT_DEFINE_ENUM_VALUE(FrameDesign, COLOR);
89
 
  SO_KIT_DEFINE_ENUM_VALUE(FrameDesign, EMBOSS);
90
 
 
91
 
  SO_KIT_SET_SF_ENUM_TYPE(design, FrameDesign);
92
 
 
93
 
  SO_KIT_ADD_CATALOG_ENTRY(scene, SoSeparator, TRUE, this, "", FALSE);
94
 
 
95
 
  SO_KIT_INIT_INSTANCE();
96
 
 
97
 
  SoNode * node = SoAny::loadSceneGraph(Frame::scene);
98
 
  assert(node);
99
 
 
100
 
  this->setAnyPart("scene", node);
101
 
 
102
 
  PRIVATE(this)->coords = (SoCoordinate3 *) SoAny::scanSceneForName(node, "coordinates");
103
 
  PRIVATE(this)->light = (SoMaterial *) SoAny::scanSceneForName(node, "light");
104
 
  PRIVATE(this)->shade = (SoMaterial *) SoAny::scanSceneForName(node, "shade");
105
 
 
106
 
  assert(PRIVATE(this)->coords);
107
 
  assert(PRIVATE(this)->light);
108
 
  assert(PRIVATE(this)->shade);
109
 
  
110
 
  PRIVATE(this)->coords->ref();
111
 
  PRIVATE(this)->light->ref();
112
 
  PRIVATE(this)->shade->ref();
113
 
 
114
 
  PRIVATE(this)->size_sensor = new SoFieldSensor(Frame::size_updated_cb, PRIVATE(this));
115
 
  PRIVATE(this)->size_sensor->attach(&(this->size));
116
 
  PRIVATE(this)->width_sensor = new SoFieldSensor(Frame::size_updated_cb, PRIVATE(this));
117
 
  PRIVATE(this)->width_sensor->attach(&(this->size));
118
 
  PRIVATE(this)->design_sensor = new SoFieldSensor(Frame::design_updated_cb, PRIVATE(this));
119
 
  PRIVATE(this)->design_sensor->attach(&(this->design));
120
 
  PRIVATE(this)->complement_sensor = new SoFieldSensor(Frame::design_updated_cb, PRIVATE(this));
121
 
  PRIVATE(this)->complement_sensor->attach(&(this->complement));
122
 
  this->design.touch();
123
 
}
124
 
 
125
 
SoGuiFrame::~SoGuiFrame(void)
126
 
{
127
 
  PRIVATE(this)->coords->unref();
128
 
  PRIVATE(this)->light->unref();
129
 
  PRIVATE(this)->shade->unref();
130
 
  delete PRIVATE(this)->size_sensor;
131
 
  delete PRIVATE(this)->width_sensor;
132
 
  delete PRIVATE(this)->design_sensor;
133
 
  delete PRIVATE(this)->complement_sensor;
134
 
  Frame * obj = PRIVATE(this);
135
 
  delete obj;
136
 
}
137
 
 
138
 
#undef PRIVATE
139
 
 
140
 
// *************************************************************************
141
 
 
142
 
#define PUBLIC(obj) ((SoGuiFrame *)obj->api)
143
 
 
144
 
const char *
145
 
Frame::scene[] =
146
 
{
147
 
  "#Inventor V2.1 ascii",
148
 
  "",
149
 
  "Separator {",
150
 
  "  DEF coordinates Coordinate3 {",
151
 
  "    point [",
152
 
  "      0 0 0,",
153
 
  "      1 0 0,",
154
 
  "      1 1 0,",
155
 
  "      0 1 0,",
156
 
  "      -1 -1 0,",
157
 
  "      2 -1 0,",
158
 
  "      2 2 0,",
159
 
  "      -1 2 0",
160
 
  "    ]",
161
 
  "  }",
162
 
  // shadow
163
 
  "  DEF shade Material {",
164
 
  "    diffuseColor 0.9 0.9 0.9",
165
 
  "  }",
166
 
  "  IndexedFaceSet {",
167
 
  "    coordIndex [",
168
 
  "      4 5 1 -1",
169
 
  "      4 1 0 -1",
170
 
  "      5 6 2 -1",
171
 
  "      5 2 1 -1",
172
 
  "    ]",
173
 
  "  }",
174
 
  // light
175
 
  "  DEF light Material {",
176
 
  "    diffuseColor 0.5 0.5 0.5",
177
 
  "  }",
178
 
  "  IndexedFaceSet {",
179
 
  "    coordIndex [",
180
 
  "      6 7 3 -1",
181
 
  "      6 3 2 -1",
182
 
  "      7 4 0 -1",
183
 
  "      7 0 3 -1",
184
 
  "    ]",
185
 
  "  }",
186
 
  "}",
187
 
  NULL
188
 
};
189
 
 
190
 
void
191
 
Frame::size_updated_cb(void * closure, SoSensor * sensor)
192
 
{
193
 
  assert(closure != NULL);
194
 
  Frame * me = (Frame *) closure;
195
 
  SoCoordinate3 * coords = me->coords;
196
 
  assert(coords);
197
 
  SbVec3f size = PUBLIC(me)->size.getValue();
198
 
  float width = PUBLIC(me)->width.getValue();
199
 
  SbBool save = coords->point.enableNotify(FALSE);
200
 
  coords->point.set1Value(1, SbVec3f(size[0], 0.0f, 0.0f));
201
 
  coords->point.set1Value(2, SbVec3f(size[0], size[1], 0.0f));
202
 
  coords->point.set1Value(3, SbVec3f(0.0f, size[1], 0.0f));
203
 
  coords->point.set1Value(4, SbVec3f(-width, -width, 0.0f));
204
 
  coords->point.set1Value(5, SbVec3f(size[0]+width, -width, 0.0f));
205
 
  coords->point.set1Value(6, SbVec3f(size[0]+width, size[1]+width, 0.0f));
206
 
  coords->point.set1Value(7, SbVec3f(-width, size[1]+width, 0.0f));
207
 
  coords->point.enableNotify(save);
208
 
  if ( save ) coords->point.touch();
209
 
}
210
 
 
211
 
void
212
 
Frame::design_updated_cb(void * closure, SoSensor * sensor)
213
 
{
214
 
  assert(closure != NULL);
215
 
  Frame * me = (Frame *) closure;
216
 
  SoMaterial * light = me->light;
217
 
  SoMaterial * shade = me->shade;
218
 
  assert(light);
219
 
  assert(shade);
220
 
  switch ( PUBLIC(me)->design.getValue() ) {
221
 
  case SoGuiFrame::EMBOSS:
222
 
    if ( PUBLIC(me)->complement.getValue() ) {
223
 
      light->diffuseColor.setValue(SbColor(0.5f, 0.5f, 0.5f));
224
 
      shade->diffuseColor.setValue(SbColor(0.9f, 0.9f, 0.9f));
225
 
    } else {
226
 
      light->diffuseColor.setValue(SbColor(0.9f, 0.9f, 0.9f));
227
 
      shade->diffuseColor.setValue(SbColor(0.5f, 0.5f, 0.5f));
228
 
    }
229
 
    break;
230
 
  case SoGuiFrame::BLACK:
231
 
    if ( PUBLIC(me)->complement.getValue() ) {
232
 
      light->diffuseColor.setValue(SbColor(1.0f, 0.0f, 0.0f));
233
 
      shade->diffuseColor.setValue(SbColor(1.0f, 0.0f, 0.0f));
234
 
    } else {
235
 
      light->diffuseColor.setValue(SbColor(0.0f, 0.0f, 0.0f));
236
 
      shade->diffuseColor.setValue(SbColor(0.0f, 0.0f, 0.0f));
237
 
    }
238
 
    break;
239
 
  default:
240
 
    break;
241
 
  }
242
 
}
243
 
 
244
 
#undef PUBLIC
245
 
 
246
 
// *************************************************************************