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

« back to all changes in this revision

Viewing changes to build/msvc6/src/Inventor/Qt/editors/SoQtColorEditor.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2006-02-06 22:34:00 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060206223400-g69m5soqa4zh0gkc
Tags: 1.3.0-3
debian/control: update libsoqt-dev depends.  Closes: #351700.

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
// FIXME: overload the getClassName() type functions
 
25
 
 
26
#include <Inventor/SbPList.h>
 
27
#include <Inventor/SoSceneManager.h>
 
28
#include <Inventor/fields/SoSFColor.h>
 
29
#include <Inventor/fields/SoMFColor.h>
 
30
#include <Inventor/fields/SoMFUInt32.h>
 
31
#include <Inventor/nodes/SoSeparator.h>
 
32
#include <Inventor/nodes/SoTexture2.h>
 
33
#include <Inventor/sensors/SoFieldSensor.h>
 
34
#include <Inventor/actions/SoGLRenderAction.h>
 
35
 
 
36
#include <Inventor/Qt/SoAny.h>
 
37
#include <Inventor/Qt/nodes/SoGuiViewportFix.h>
 
38
#include <Inventor/Qt/nodes/SoGuiColorEditor.h>
 
39
#include <Inventor/Qt/editors/SoQtColorEditor.h>
 
40
 
 
41
/*
 
42
#include <Inventor/Qt/nodes/SoGuiPane.h>
 
43
#include <Inventor/Qt/nodes/SoGuiClickCounter.h>
 
44
#include <Inventor/Qt/nodes/SoGuiSlider1.h>
 
45
#include <Inventor/Qt/nodes/SoGuiSlider2.h>
 
46
*/
 
47
 
 
48
 
 
49
/*!
 
50
  \class SoQtColorEditor Inventor/Qt/editors/SoQtColorEditor.h
 
51
  \brief The SoQtColorEditor class is a GUI component for interactively
 
52
  editing color fields.
 
53
*/
 
54
 
 
55
/*!
 
56
  \enum SoQtColorEditor::Sliders
 
57
*/
 
58
 
 
59
/*!
 
60
  \val SoQtColorEditor::NONE
 
61
*/
 
62
 
 
63
/*!
 
64
  \val SoQtColorEditor::INTENSITY
 
65
*/
 
66
 
 
67
/*!
 
68
  \val SoQtColorEditor::RGB
 
69
*/
 
70
 
 
71
/*!
 
72
  \val SoQtColorEditor::HSV
 
73
*/
 
74
 
 
75
/*!
 
76
  \val SoQtColorEditor::RGB_V
 
77
*/
 
78
 
 
79
/*!
 
80
  \val SoQtColorEditor::RGB_HSV
 
81
*/
 
82
 
 
83
/*!
 
84
  \enum SoQtColorEditor::UpdateFrequency
 
85
*/
 
86
 
 
87
/*!
 
88
  \val SoQtColorEditor::CONTINUOUS
 
89
*/
 
90
 
 
91
/*!
 
92
  \val SoQtColorEditor::AFTER_ACCEPT
 
93
*/
 
94
 
 
95
// *************************************************************************
 
96
 
 
97
static const SbBool SGI_ATTACHMENT_REF_COMPATIBILITY = TRUE;
 
98
 
 
99
enum Attachment {
 
100
  DETACHED,
 
101
  SFCOLOR,
 
102
  MFCOLOR,
 
103
  MFUINT32
 
104
};
 
105
 
 
106
// Name suffix used to avoid conflict with private part of the ColorEditor
 
107
// node kit.
 
108
 
 
109
class ColorEditorComponent {
 
110
public:
 
111
  SoQtColorEditor * api;
 
112
 
 
113
  static const char * superscene[];
 
114
 
 
115
  SbPList callbacks;
 
116
 
 
117
  // attachment is redundant - the existence of the field sensor, and the
 
118
  // field type it is attached to is all the info needed really
 
119
  Attachment attachment;
 
120
  // the field pointers can actually be dropped since the sensor will have
 
121
  // that info
 
122
  SoSFColor * sfcolor;
 
123
  SoMFColor * mfcolor;
 
124
  SoMFUInt32 * mfuint32;
 
125
  int mfindex;
 
126
 
 
127
  SoFieldSensor * editor_sensor;
 
128
  static void editor_update_cb(void * closure, SoSensor * sensor);
 
129
 
 
130
  SoFieldSensor * attachment_sensor;
 
131
  static void attachment_update_cb(void * closure, SoSensor * sensor);
 
132
 
 
133
  SoGuiColorEditor * editor;
 
134
 
 
135
  void invokeColorChangeCallbacks(void);
 
136
  SbBool colorsEqual(void);
 
137
};
 
138
 
 
139
// *************************************************************************
 
140
 
 
141
SOQT_OBJECT_SOURCE(SoQtColorEditor);
 
142
 
 
143
#define PRIVATE(obj) ((ColorEditorComponent *) ((SoQtColorEditor *) obj)->internals)
 
144
#define PUBLIC(obj) (((ColorEditorComponent *) obj)->api)
 
145
 
 
146
SoQtColorEditor::SoQtColorEditor(QWidget * parent, const char * name, SbBool embed)
 
147
  : inherited(parent, name, embed)
 
148
{
 
149
  this->internals = (void *) new ColorEditorComponent;
 
150
  PRIVATE(this)->api = this;
 
151
 
 
152
  PRIVATE(this)->attachment = DETACHED;
 
153
  PRIVATE(this)->sfcolor = NULL;
 
154
  PRIVATE(this)->sfcolor = NULL;
 
155
  PRIVATE(this)->mfcolor = NULL;
 
156
  PRIVATE(this)->mfuint32 = NULL;
 
157
  PRIVATE(this)->mfindex = 0;
 
158
 
 
159
  PRIVATE(this)->editor_sensor = NULL;
 
160
  PRIVATE(this)->attachment_sensor = NULL;
 
161
 
 
162
  PRIVATE(this)->editor = NULL;
 
163
 
 
164
  this->setSize(SbVec2s(320, 256));
 
165
 
 
166
  SoNode * root = SoAny::loadSceneGraph(ColorEditorComponent::superscene);
 
167
  assert(root != NULL);
 
168
  assert(root->isOfType(SoSeparator::getClassTypeId()));
 
169
  SoSeparator * superscene = (SoSeparator *) root;
 
170
 
 
171
  PRIVATE(this)->editor = new SoGuiColorEditor;
 
172
  superscene->addChild(PRIVATE(this)->editor);
 
173
  this->setSceneGraph(superscene);
 
174
 
 
175
  PRIVATE(this)->attachment_sensor = new SoFieldSensor(ColorEditorComponent::attachment_update_cb, PRIVATE(this));
 
176
 
 
177
  PRIVATE(this)->editor_sensor = new SoFieldSensor(ColorEditorComponent::editor_update_cb, PRIVATE(this));
 
178
  PRIVATE(this)->editor_sensor->attach(&(PRIVATE(this)->editor->color));
 
179
}
 
180
 
 
181
SoQtColorEditor::~SoQtColorEditor(void)
 
182
{
 
183
  if ( PRIVATE(this)->attachment != DETACHED ) this->detach();
 
184
  delete PRIVATE(this)->attachment_sensor;
 
185
  delete PRIVATE(this)->editor_sensor;
 
186
  this->setSceneGraph(NULL);
 
187
  ColorEditorComponent * instance = PRIVATE(this);
 
188
  delete instance;
 
189
}
 
190
 
 
191
/*!
 
192
  Attach the editor to a color single field.  Any existing attachments are
 
193
  detached.
 
194
 
 
195
  The node argument defaults to NULL and is ignored.  It is part of the
 
196
  argument list for compatibility reasons.
 
197
*/
 
198
 
 
199
void
 
200
SoQtColorEditor::attach(SoSFColor * color, SoBase * node)
 
201
{
 
202
  if ( PRIVATE(this)->attachment != DETACHED ) this->detach();
 
203
  if ( color != NULL ) {
 
204
    if ( SGI_ATTACHMENT_REF_COMPATIBILITY ) {
 
205
      SoFieldContainer * container = color->getContainer();
 
206
      if ( container != NULL ) container->ref();
 
207
    }
 
208
    PRIVATE(this)->attachment = SFCOLOR;
 
209
    PRIVATE(this)->sfcolor = color;
 
210
    assert(PRIVATE(this)->attachment_sensor != NULL);
 
211
    PRIVATE(this)->attachment_sensor->attach(color);
 
212
    PRIVATE(this)->editor->color.setValue(color->getValue());
 
213
  }
 
214
}
 
215
 
 
216
/*!
 
217
  Attach the editor to an element in a color multi field.  Any existing attachments are
 
218
  detached.
 
219
  
 
220
  The node argument defaults to NULL and is ignored.  It is part of the
 
221
  argument list for compatibility reasons.
 
222
*/
 
223
 
 
224
void
 
225
SoQtColorEditor::attach(SoMFColor * color, int idx, SoBase * node)
 
226
{
 
227
  if ( PRIVATE(this)->attachment != DETACHED ) this->detach();
 
228
  if ( color != NULL ) {
 
229
    if ( SGI_ATTACHMENT_REF_COMPATIBILITY ) {
 
230
      SoFieldContainer * container = color->getContainer();
 
231
      if ( container != NULL ) container->ref();
 
232
    }
 
233
    PRIVATE(this)->attachment = MFCOLOR;
 
234
    PRIVATE(this)->mfcolor = color;
 
235
    PRIVATE(this)->mfindex = idx;
 
236
    assert(PRIVATE(this)->attachment_sensor != NULL);
 
237
    PRIVATE(this)->attachment_sensor->attach(color);
 
238
    PRIVATE(this)->editor->color.setValue(color->operator[](idx));
 
239
  }
 
240
}
 
241
 
 
242
/*!
 
243
  Attach the editor to an element in an uint32 multi field.  The field
 
244
  is assumed to be of the RGBA packed color format.  Any existing attachments are
 
245
  detached.
 
246
  
 
247
  The node argument defaults to NULL and is ignored.  It is part of the
 
248
  argument list for compatibility reasons.
 
249
*/
 
250
 
 
251
void
 
252
SoQtColorEditor::attach(SoMFUInt32 * color, int idx, SoBase * node)
 
253
{
 
254
  if ( PRIVATE(this)->attachment != DETACHED ) this->detach();
 
255
  if ( color != NULL ) {
 
256
    if ( SGI_ATTACHMENT_REF_COMPATIBILITY ) {
 
257
      SoFieldContainer * container = color->getContainer();
 
258
      if ( container != NULL ) container->ref();
 
259
    }
 
260
    PRIVATE(this)->attachment = MFUINT32;
 
261
    PRIVATE(this)->mfuint32 = color;
 
262
    PRIVATE(this)->mfindex = idx;
 
263
    assert(PRIVATE(this)->attachment_sensor != NULL);
 
264
    PRIVATE(this)->attachment_sensor->attach(color);
 
265
    SbColor col;
 
266
    float transparency = 0.0f;
 
267
    col.setPackedValue(color->operator[](idx), transparency);
 
268
    PRIVATE(this)->editor->color.setValue(col);
 
269
  }
 
270
}
 
271
 
 
272
/*!
 
273
  Detach the editor from the field it is attached to.
 
274
*/
 
275
 
 
276
void
 
277
SoQtColorEditor::detach(void)
 
278
{
 
279
  if ( PRIVATE(this)->attachment != DETACHED ) {
 
280
    SoField * field = NULL;
 
281
    switch ( PRIVATE(this)->attachment ) {
 
282
    case SFCOLOR:
 
283
      field = PRIVATE(this)->sfcolor;
 
284
      PRIVATE(this)->sfcolor = NULL;
 
285
      break;
 
286
    case MFCOLOR:
 
287
      field = PRIVATE(this)->mfcolor;
 
288
      PRIVATE(this)->mfcolor = NULL;
 
289
      break;
 
290
    case MFUINT32:
 
291
      field = PRIVATE(this)->mfuint32;
 
292
      PRIVATE(this)->mfuint32 = NULL;
 
293
      break;
 
294
    case DETACHED:
 
295
    default:
 
296
      assert(0 && "impossible switch case");
 
297
      break;
 
298
    }
 
299
    assert(field != NULL);
 
300
    if ( field != NULL ) {
 
301
      assert(PRIVATE(this)->attachment_sensor != NULL);
 
302
      PRIVATE(this)->attachment_sensor->detach();
 
303
      if ( SGI_ATTACHMENT_REF_COMPATIBILITY ) {
 
304
        SoFieldContainer * container = field->getContainer();
 
305
        if ( container != NULL ) container->unref();
 
306
      }
 
307
    }
 
308
    PRIVATE(this)->attachment = DETACHED;
 
309
  }
 
310
}
 
311
 
 
312
/*!
 
313
  This method returns whether or not the editor is currently attached to a field.
 
314
*/
 
315
 
 
316
SbBool
 
317
SoQtColorEditor::isAttached(void) const
 
318
{
 
319
  return (PRIVATE(this)->attachment != DETACHED) ? TRUE : FALSE;
 
320
}
 
321
 
 
322
/*
 
323
  Add a callback to be triggered when the color value is changed.
 
324
 
 
325
  \sa SoQtColorEditor::setUpdateFrequency
 
326
*/
 
327
 
 
328
void
 
329
SoQtColorEditor::addColorChangedCallback(SoQtColorEditorCB * callback, void * closure)
 
330
{
 
331
  PRIVATE(this)->callbacks.append((void *) callback);
 
332
  PRIVATE(this)->callbacks.append(closure);
 
333
}
 
334
 
 
335
/*!
 
336
  Remove all color change callbacks matching the given arguments.
 
337
*/
 
338
 
 
339
void
 
340
SoQtColorEditor::removeColorChangedCallback(SoQtColorEditorCB * callback, void * closure)
 
341
{
 
342
  const int len = PRIVATE(this)->callbacks.getLength();
 
343
  int i;
 
344
  for ( i = 0; i < len; i += 2 ) {
 
345
    SoQtColorEditorCB * cb =
 
346
      (SoQtColorEditorCB *) PRIVATE(this)->callbacks[i];
 
347
    if ( (callback == cb) && (closure == PRIVATE(this)->callbacks[i+1]) ) {
 
348
      PRIVATE(this)->callbacks.remove(i+1);
 
349
      PRIVATE(this)->callbacks.remove(i);
 
350
      i -= 2;
 
351
    }
 
352
  }
 
353
}
 
354
 
 
355
/*!
 
356
  Set a new color value.
 
357
 
 
358
  If the field value gets updated, the color change callbacks will be triggered.
 
359
*/
 
360
 
 
361
void
 
362
SoQtColorEditor::setColor(const SbColor & color)
 
363
{
 
364
  // callbacks are triggered on the sensor rebound...
 
365
  switch ( PRIVATE(this)->attachment ) {
 
366
  case DETACHED:
 
367
    break;
 
368
  case SFCOLOR:
 
369
    assert(PRIVATE(this)->sfcolor != NULL);
 
370
    if ( PRIVATE(this)->sfcolor->getValue() != color ) {
 
371
      PRIVATE(this)->sfcolor->setValue(color);
 
372
    }
 
373
    break;
 
374
  case MFCOLOR:
 
375
    assert(PRIVATE(this)->mfcolor != NULL);
 
376
    if ( PRIVATE(this)->mfcolor->operator[](PRIVATE(this)->mfindex) != color ) {
 
377
      PRIVATE(this)->mfcolor->set1Value(PRIVATE(this)->mfindex, color);
 
378
    }
 
379
    break;
 
380
  case MFUINT32:
 
381
    assert(PRIVATE(this)->mfuint32 != NULL);
 
382
    if ( PRIVATE(this)->mfuint32->operator[](PRIVATE(this)->mfindex) != color.getPackedValue() ) {
 
383
      PRIVATE(this)->mfuint32->set1Value(PRIVATE(this)->mfindex, color.getPackedValue());
 
384
    }
 
385
    break;
 
386
  }
 
387
  assert(PRIVATE(this)->editor != NULL);
 
388
  PRIVATE(this)->editor->color.setValue(color);
 
389
}
 
390
 
 
391
/*!
 
392
  Get the current color value.
 
393
*/
 
394
 
 
395
const SbColor &
 
396
SoQtColorEditor::getColor(void) const
 
397
{
 
398
  assert(PRIVATE(this)->editor != NULL);
 
399
  return PRIVATE(this)->editor->color.getValue();
 
400
}
 
401
 
 
402
/*!
 
403
  Not implemented yet.
 
404
 
 
405
  Sets whether or not the color sliders should be in WYSIWYG mode.
 
406
  When enabled, the color backgrounds in the sliders will be updated to
 
407
  reflect what the color will be, taken all color components into account.
 
408
  When disabled, the color backgrounds only reflect the component the slider
 
409
  controls.
 
410
*/
 
411
 
 
412
void
 
413
SoQtColorEditor::setWYSIWYG(SbBool enable)
 
414
{
 
415
  assert(PRIVATE(this)->editor != NULL);
 
416
  PRIVATE(this)->editor->wysiwyg.setValue(enable);
 
417
}
 
418
 
 
419
/*!
 
420
  Returns whether or not the editor sliders are in WYSIWYG mode.
 
421
*/
 
422
 
 
423
SbBool
 
424
SoQtColorEditor::isWYSIWYG(void) const
 
425
{
 
426
  assert(PRIVATE(this)->editor != NULL);
 
427
  return PRIVATE(this)->editor->wysiwyg.getValue();
 
428
}
 
429
 
 
430
/*!
 
431
  Sets which if the slider sets is to be used.
 
432
 
 
433
  \sa SoQtColorEditor::Sliders
 
434
*/
 
435
 
 
436
void
 
437
SoQtColorEditor::setCurrentSliders(SoQtColorEditor::Sliders which)
 
438
{
 
439
  assert(PRIVATE(this)->editor != NULL);
 
440
  PRIVATE(this)->editor->sliders.setValue((SoQtColorEditor::Sliders) which);
 
441
}
 
442
 
 
443
/*!
 
444
  Returns which slider sets is being used.
 
445
 
 
446
  \sa SoQtColorEditor::Sliders
 
447
*/
 
448
 
 
449
SoQtColorEditor::Sliders
 
450
SoQtColorEditor::getCurrentSliders(void) const
 
451
{
 
452
  assert(PRIVATE(this)->editor != NULL);
 
453
  return (SoQtColorEditor::Sliders) PRIVATE(this)->editor->sliders.getValue();
 
454
}
 
455
 
 
456
/*!
 
457
  Sets the update-frequency setting, which affects when color change callbacks
 
458
  will be triggered.
 
459
 
 
460
  \sa SoQtColorEditor::UpdateFrequency
 
461
*/
 
462
 
 
463
void
 
464
SoQtColorEditor::setUpdateFrequency(SoQtColorEditor::UpdateFrequency freq)
 
465
{
 
466
  assert(PRIVATE(this)->editor != NULL);
 
467
  PRIVATE(this)->editor->update.setValue((SoQtColorEditor::UpdateFrequency) freq);
 
468
}
 
469
 
 
470
/*!
 
471
  Returns the update-frequency setting.
 
472
 
 
473
  \sa SoQtColorEditor::UpdateFrequency
 
474
*/
 
475
 
 
476
SoQtColorEditor::UpdateFrequency
 
477
SoQtColorEditor::getUpdateFrequency(void) const
 
478
{
 
479
  assert(PRIVATE(this)->editor != NULL);
 
480
  return (SoQtColorEditor::UpdateFrequency) PRIVATE(this)->editor->update.getValue();
 
481
}
 
482
 
 
483
SoGuiColorEditor *
 
484
SoQtColorEditor::getEditor(void) const
 
485
{
 
486
  return PRIVATE(this)->editor;
 
487
}
 
488
 
 
489
// *************************************************************************
 
490
 
 
491
const char *
 
492
SoQtColorEditor::getDefaultWidgetName(void) const
 
493
{
 
494
  static const char widgetName[] = "SoQtColorEditor";
 
495
  return widgetName;
 
496
}
 
497
 
 
498
const char *
 
499
SoQtColorEditor::getDefaultTitle(void) const
 
500
{
 
501
  static const char title[] = "ColorEditor";
 
502
  return title;
 
503
}
 
504
 
 
505
const char *
 
506
SoQtColorEditor::getDefaultIconTitle(void) const
 
507
{
 
508
  static const char iconTitle[] = "ColEd";
 
509
  return iconTitle;
 
510
}
 
511
 
 
512
// *************************************************************************
 
513
// ColorEditorComponent
 
514
// *************************************************************************
 
515
 
 
516
const char *
 
517
ColorEditorComponent::superscene[] =
 
518
{
 
519
  "#Inventor V2.1 ascii",
 
520
  "",
 
521
  "Separator {",
 
522
  "  DirectionalLight { direction 0 0 -1 color 1 1 1 intensity 0.8 }",
 
523
  "  OrthographicCamera { }",
 
524
  "  DEF viewportfix SoGuiViewportFix { }",
 
525
  "  Material { ambientColor 0.8 0.8 0.8 }",
 
526
  "}",
 
527
  NULL
 
528
};
 
529
 
 
530
// *************************************************************************
 
531
 
 
532
void
 
533
ColorEditorComponent::invokeColorChangeCallbacks(void)
 
534
{
 
535
  int i;
 
536
  for ( i = 0; i < this->callbacks.getLength(); i += 2 ) {
 
537
    SoQtColorEditorCB * callback = (SoQtColorEditorCB *) this->callbacks[i];
 
538
    void * closure = this->callbacks[i+1];
 
539
    callback(closure, &this->editor->color.getValue());
 
540
  }
 
541
}
 
542
 
 
543
SbBool
 
544
ColorEditorComponent::colorsEqual(void)
 
545
{
 
546
  SbColor attachmentColor;
 
547
  switch ( this->attachment ) {
 
548
  case SFCOLOR:
 
549
    assert(this->sfcolor != NULL);
 
550
    attachmentColor = this->sfcolor->getValue();
 
551
    break;
 
552
  case MFCOLOR:
 
553
    assert(this->mfcolor != NULL);
 
554
    attachmentColor = this->mfcolor->operator[](this->mfindex);
 
555
    break;
 
556
  case MFUINT32:
 
557
    assert(this->mfcolor != NULL);
 
558
    do {
 
559
      float transparency = 0.0f;
 
560
      attachmentColor.setPackedValue(this->mfuint32->operator[](this->mfindex), transparency);
 
561
    } while ( FALSE );
 
562
    break;
 
563
  case DETACHED:
 
564
  default:
 
565
    return TRUE;
 
566
  }
 
567
  return (attachmentColor == this->editor->color.getValue()) ? TRUE : FALSE;
 
568
}
 
569
 
 
570
void
 
571
ColorEditorComponent::attachment_update_cb(void * closure, SoSensor * sensor)
 
572
{
 
573
  assert(closure != NULL);
 
574
  ColorEditorComponent * me = (ColorEditorComponent *) closure;
 
575
  if ( me->colorsEqual() ) return;
 
576
 
 
577
  switch ( me->attachment ) {
 
578
  case SFCOLOR:
 
579
    assert(me->sfcolor != NULL);
 
580
    me->editor->color.setValue(me->sfcolor->getValue());
 
581
    break;
 
582
  case MFCOLOR:
 
583
    assert(me->mfcolor != NULL);
 
584
    me->editor->color.setValue(me->mfcolor->operator[](me->mfindex));
 
585
    break;
 
586
  case MFUINT32:
 
587
    assert(me->mfcolor != NULL);
 
588
    do {
 
589
      SbColor color;
 
590
      float transparency = 0.0f;
 
591
      color.setPackedValue(me->mfuint32->operator[](me->mfindex), transparency);
 
592
      me->editor->color.setValue(color);
 
593
    } while ( FALSE );
 
594
    break;
 
595
  case DETACHED:
 
596
  default:
 
597
    break;
 
598
  }
 
599
}
 
600
 
 
601
void
 
602
ColorEditorComponent::editor_update_cb(void * closure, SoSensor * sensor)
 
603
{
 
604
  assert(closure != NULL);
 
605
  ColorEditorComponent * me = (ColorEditorComponent *) closure;
 
606
  if ( me->colorsEqual() ) return;
 
607
 
 
608
  SbColor color = me->editor->color.getValue();
 
609
 
 
610
  switch ( me->attachment ) {
 
611
  case SFCOLOR:
 
612
    assert(me->sfcolor != NULL);
 
613
    me->sfcolor->setValue(color);
 
614
    break;
 
615
  case MFCOLOR:
 
616
    assert(me->mfcolor != NULL);
 
617
    me->mfcolor->set1Value(me->mfindex, color);
 
618
    break;
 
619
  case MFUINT32:
 
620
    assert(me->mfuint32 != NULL);
 
621
    me->mfuint32->set1Value(me->mfindex, color.getPackedValue());
 
622
    break;
 
623
  case DETACHED:
 
624
  default:
 
625
    break;
 
626
  }
 
627
 
 
628
  if ( me->editor->update.getValue() == SoGuiColorEditor::CONTINUOUS )
 
629
    me->invokeColorChangeCallbacks();
 
630
}
 
631
 
 
632
// *************************************************************************
 
633
 
 
634
#undef PRIVATE
 
635
#undef PUBLIC
 
636