1
/**************************************************************************\
3
* This file is part of the Coin 3D visualization library.
4
* Copyright (C) 1998-2005 by Systems in Motion. All rights reserved.
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.
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.
17
* See <URL:http://www.coin3d.org/> for more information.
19
* Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
20
* <URL:http://www.sim.no/>.
22
\**************************************************************************/
26
#endif // HAVE_CONFIG_H
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>
37
#include <Inventor/Qt/common/gl.h>
38
#include <Inventor/Qt/SoAny.h>
39
#include <Inventor/Qt/nodes/SoGuiFrame.h>
42
// *************************************************************************
48
SoCoordinate3 * coords;
52
SoFieldSensor * size_sensor;
53
SoFieldSensor * width_sensor;
54
static void size_updated_cb(void * closure, SoSensor * sensor);
56
SoFieldSensor * design_sensor;
57
static void design_updated_cb(void * closure, SoSensor * sensor);
58
SoFieldSensor * complement_sensor;
60
static const char * scene[];
63
// *************************************************************************
65
#define PRIVATE(obj) ((Frame *)obj->internals)
68
SoGuiFrame::initClass(void)
70
SO_KIT_INIT_CLASS(SoGuiFrame, SoBaseKit, "BaseKit");
73
SO_KIT_SOURCE(SoGuiFrame);
75
SoGuiFrame::SoGuiFrame(void)
77
this->internals = new Frame;
78
PRIVATE(this)->api = this;
80
SO_KIT_CONSTRUCTOR(SoGuiFrame);
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));
87
SO_KIT_DEFINE_ENUM_VALUE(FrameDesign, BLACK);
88
SO_KIT_DEFINE_ENUM_VALUE(FrameDesign, COLOR);
89
SO_KIT_DEFINE_ENUM_VALUE(FrameDesign, EMBOSS);
91
SO_KIT_SET_SF_ENUM_TYPE(design, FrameDesign);
93
SO_KIT_ADD_CATALOG_ENTRY(scene, SoSeparator, TRUE, this, "", FALSE);
95
SO_KIT_INIT_INSTANCE();
97
SoNode * node = SoAny::loadSceneGraph(Frame::scene);
100
this->setAnyPart("scene", node);
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");
106
assert(PRIVATE(this)->coords);
107
assert(PRIVATE(this)->light);
108
assert(PRIVATE(this)->shade);
110
PRIVATE(this)->coords->ref();
111
PRIVATE(this)->light->ref();
112
PRIVATE(this)->shade->ref();
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();
125
SoGuiFrame::~SoGuiFrame(void)
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);
140
// *************************************************************************
142
#define PUBLIC(obj) ((SoGuiFrame *)obj->api)
147
"#Inventor V2.1 ascii",
150
" DEF coordinates Coordinate3 {",
163
" DEF shade Material {",
164
" diffuseColor 0.9 0.9 0.9",
175
" DEF light Material {",
176
" diffuseColor 0.5 0.5 0.5",
191
Frame::size_updated_cb(void * closure, SoSensor * sensor)
193
assert(closure != NULL);
194
Frame * me = (Frame *) closure;
195
SoCoordinate3 * coords = me->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();
212
Frame::design_updated_cb(void * closure, SoSensor * sensor)
214
assert(closure != NULL);
215
Frame * me = (Frame *) closure;
216
SoMaterial * light = me->light;
217
SoMaterial * shade = me->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));
226
light->diffuseColor.setValue(SbColor(0.9f, 0.9f, 0.9f));
227
shade->diffuseColor.setValue(SbColor(0.5f, 0.5f, 0.5f));
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));
235
light->diffuseColor.setValue(SbColor(0.0f, 0.0f, 0.0f));
236
shade->diffuseColor.setValue(SbColor(0.0f, 0.0f, 0.0f));
246
// *************************************************************************