~ubuntu-branches/ubuntu/oneiric/nux/oneiric

« back to all changes in this revision

Viewing changes to Nux/PropertyItem/RGBProperty.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2011-06-22 17:16:16 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20110622171616-3cyhhiwsb6ga9d30
Tags: 1.0.2-0ubuntu1
* New upstream release.
* Cherry-pick a fix for FTBFS with -fpermissive
* debian/control:
  - add new libxdamage-dev and libxcomposite-dev build-dep
  - add new libboost1.42-dev dep as well, should be transitionned to 1.46 once
    compiz is transitionned as well
* remove debian/patches/01_build_with_gcc46.patch as included upstream
* debian/rules:
  - disable google code tests while building
* debian/control, debian/rules, debian/libnux-1.0-common.install,
  debian/libnux-1.0-dev.install, debian/libnux-1.0-doc.install,
  debian/libnux-1.0-0.install:
  - change, prepare next ABI breakage and remove no more needed Breaks: with
    new soname bump
* libnux-1.0-common now replaces: libnux-0.9-common for the apport hook

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
{
30
30
 
31
31
  RGBPropertyItem::RGBPropertyItem (const TCHAR *name, float red /* = 1.0f*/, float green /* = 1.0f*/, float blue /* = 1.0f*/)
32
 
    :   SectionProperty (name, NODE_TYPE_RGB)
33
 
    ,   m_color_model (CM_RGB)
34
 
    ,   m_color_format (Color::COLORFORMAT_FLOAT)
 
32
    : SectionProperty (name, NODE_TYPE_RGB)
 
33
    , rgb_values_(red, green, blue)
 
34
    , color_model_(color::RGB)
 
35
    , color_format_(color::FLOAT)
35
36
  {
36
37
    m_red = new ColorGradientPropertyItem (TEXT ("Red") );
37
38
    m_green = new ColorGradientPropertyItem (TEXT ("Green") );
44
45
    m_ColorFormat->SetMinMaxSize (32, 14);
45
46
    m_ColorFormat->SetFont (GetSysBoldFont() );
46
47
 
47
 
 
48
48
    PushChildBack (m_red);
49
49
    PushChildBack (m_green);
50
50
    PushChildBack (m_blue);
60
60
    m_blue->SetRange (0.0f, 1.0f);
61
61
    m_blue->SetValue (b);
62
62
 
63
 
    m_red->SetColorFormat (m_color_format);
64
 
    m_green->SetColorFormat (m_color_format);
65
 
    m_blue->SetColorFormat (m_color_format);
 
63
    m_red->SetColorFormat (color_format_);
 
64
    m_green->SetColorFormat (color_format_);
 
65
    m_blue->SetColorFormat (color_format_);
66
66
 
67
67
    m_red->AddColorMark (0, Color (0.0f, g, b), false);
68
68
    m_red->AddColorMark (1, Color (1.0f, g, b), false);
69
 
    m_red->AddColorMark (0, Color (0.0f, g, b), false);
70
 
    m_red->AddColorMark (1, Color (1.0f, g, b), false);
71
69
    m_green->AddColorMark (0, Color (r, 0.0f, b), false);
72
70
    m_green->AddColorMark (1, Color (r, 1.0f, b), false);
73
71
    m_blue->AddColorMark (0, Color (r, g, 0.0f), false);
195
193
        prop_geo.OffsetSize ( - 2 - m_ColorFormat->GetBaseWidth() - 2 - m_ColorModel->GetBaseWidth() - 2, 0);
196
194
 
197
195
        // Draw the resulting color
198
 
        Painter.Paint2DQuadColor (GfxContext, prop_geo, Color (m_Red, m_Green, m_Blue) );
 
196
        Painter.Paint2DQuadColor (GfxContext, prop_geo, Color(rgb_values_) );
199
197
        // Draw black border around the color
200
 
        Painter.Paint2DQuadWireframe (GfxContext, prop_geo, Color (0) );
 
198
        Painter.Paint2DQuadWireframe (GfxContext, prop_geo, color::Black );
201
199
        m_ColorModel->ProcessDraw (GfxContext, true);
202
200
        m_ColorFormat->ProcessDraw (GfxContext, true);
203
201
      }
208
206
 
209
207
  void RGBPropertyItem::OnChangeColorModel()
210
208
  {
211
 
    if (m_color_model == CM_RGB)
212
 
    {
213
 
      SetColorModel (CM_HLS);
214
 
      float H, L, S;
215
 
      RGBtoHLS (m_red->GetValue(), m_green->GetValue(), m_blue->GetValue(), H, L, S);
216
 
      m_red->SetValue (H);
217
 
      m_green->SetValue (L);
218
 
      m_blue->SetValue (S);
219
 
    }
220
 
    else if (m_color_model == CM_HLS)
221
 
    {
222
 
      SetColorModel (CM_HSV);
223
 
      float H, S, V;
224
 
      float R, G, B;
225
 
      HLStoRGB (R, G, B, m_red->GetValue(), m_green->GetValue(), m_blue->GetValue() );
226
 
      RGBtoHSV (R, G, B, H, S, V);
227
 
      m_red->SetValue (H);
228
 
      m_green->SetValue (S);
229
 
      m_blue->SetValue (V);
230
 
 
231
 
      if (H == -1.0f)
232
 
      {
233
 
        H = 0;
234
 
      }
235
 
    }
236
 
    else if (m_color_model == CM_HSV)
237
 
    {
238
 
      SetColorModel (CM_RGB);
239
 
      float R, G, B;
240
 
      HSVtoRGB (R, G, B, m_red->GetValue(), m_green->GetValue(), m_blue->GetValue() );
241
 
      m_red->SetValue (R);
242
 
      m_green->SetValue (G);
243
 
      m_blue->SetValue (B);
244
 
 
245
 
    }
246
 
 
247
 
    UpdateStartToEndColors();
 
209
    if (color_model_ == color::RGB)
 
210
    {
 
211
      SetColorModel(color::HLS);
 
212
      color::HueLightnessSaturation hls(rgb_values_);
 
213
      SetColor(hls.hue, hls.lightness, hls.saturation);
 
214
    }
 
215
    else if (color_model_ == color::HLS)
 
216
    {
 
217
      SetColorModel (color::HSV);
 
218
      color::HueSaturationValue hsv(rgb_values_);
 
219
      SetColor(hsv.hue, hsv.saturation, hsv.value);
 
220
    }
 
221
    else if (color_model_ == color::HSV)
 
222
    {
 
223
      SetColorModel (color::RGB);
 
224
      SetColor(rgb_values_.red, rgb_values_.green, rgb_values_.blue);
 
225
    }
 
226
 
248
227
    m_green->NeedRedraw();
249
228
    m_blue->NeedRedraw();
250
229
  }
251
230
 
252
 
  void RGBPropertyItem::SetColorModel (eColorModel cm)
253
 
  {
254
 
    if (cm == CM_RGB)
 
231
void RGBPropertyItem::SetColorModel(color::Model cm)
 
232
{
 
233
    color_model_ = cm;
 
234
    if (cm == color::RGB)
255
235
    {
256
 
      m_color_model = CM_RGB;
257
236
      m_ColorModel->SetCaption (TEXT ("RGB") );
258
237
 
259
238
      m_red->SetName (TEXT ("Red") );
261
240
      m_blue->SetName (TEXT ("Blue") );
262
241
    }
263
242
 
264
 
    if (cm == CM_HSV)
 
243
    if (cm == color::HSV)
265
244
    {
266
 
      m_color_model = CM_HSV;
267
245
      m_ColorModel->SetCaption (TEXT ("HSV") );
268
246
 
269
247
      m_red->SetName (TEXT ("Hue") );
271
249
      m_blue->SetName (TEXT ("Value") );
272
250
    }
273
251
 
274
 
    if (cm == CM_HLS)
 
252
    if (cm == color::HLS)
275
253
    {
276
 
      m_color_model = CM_HLS;
277
254
      m_ColorModel->SetCaption (TEXT ("HLS") );
278
255
 
279
256
      m_red->SetName (TEXT ("Hue") );
281
258
      m_blue->SetName (TEXT ("Saturation") );
282
259
    }
283
260
 
284
 
    if (cm == CM_YUV)
 
261
    if (cm == color::YUV)
285
262
    {
286
 
      m_color_model = CM_YUV;
287
263
      m_ColorModel->SetBaseString (TEXT ("YUV") );
288
264
 
289
265
      //         m_ComponentLabel0->SetBaseString(TEXT("Y"));
296
272
 
297
273
  void RGBPropertyItem::OnChangeColorFormat()
298
274
  {
299
 
    if (m_color_format == Color::COLORFORMAT_FLOAT)
 
275
    if (color_format_ == color::FLOAT)
300
276
    {
301
 
      m_color_format = Color::COLORFORMAT_INT;
 
277
      color_format_ = color::INT;
302
278
      m_ColorFormat->SetCaption (TEXT ("int") );
303
279
    }
304
 
    else if (m_color_format == Color::COLORFORMAT_INT)
 
280
    else if (color_format_ == color::INT)
305
281
    {
306
 
      m_color_format = Color::COLORFORMAT_HEX;
 
282
      color_format_ = color::HEX;
307
283
      m_ColorFormat->SetCaption (TEXT ("hex") );
308
284
    }
309
 
    else if (m_color_format == Color::COLORFORMAT_HEX)
 
285
    else if (color_format_ == color::HEX)
310
286
    {
311
 
      m_color_format = Color::COLORFORMAT_FLOAT;
 
287
      color_format_ = color::FLOAT;
312
288
      m_ColorFormat->SetCaption (TEXT ("float") );
313
289
    }
314
290
 
315
 
    m_red->SetColorFormat (m_color_format);
316
 
    m_green->SetColorFormat (m_color_format);
317
 
    m_blue->SetColorFormat (m_color_format);
 
291
    m_red->SetColorFormat (color_format_);
 
292
    m_green->SetColorFormat (color_format_);
 
293
    m_blue->SetColorFormat (color_format_);
318
294
  }
319
295
 
320
296
  void RGBPropertyItem::UpdateStartToEndColors()
323
299
    m_green->Reset();
324
300
    m_blue->Reset();
325
301
 
326
 
    if (m_color_model == CM_RGB)
327
 
    {
328
 
      float r, g, b;
329
 
      r = m_red->GetValue();
330
 
      g = m_green->GetValue();
331
 
      b = m_blue->GetValue();
332
 
 
333
 
      m_red->AddColorMark (0, Color (0.0f, g, b), false);
334
 
      m_red->AddColorMark (1, Color (1.0f, g, b), false);
335
 
      m_green->AddColorMark (0, Color (r, 0.0f, b), false);
336
 
      m_green->AddColorMark (1, Color (r, 1.0f, b), false);
337
 
      m_blue->AddColorMark (0, Color (r, g, 0.0f), false);
338
 
      m_blue->AddColorMark (1, Color (r, g, 1.0f), false);
339
 
 
340
 
      m_Red = r;
341
 
      m_Green = g;
342
 
      m_Blue = b;
343
 
    }
344
 
 
345
 
    if (m_color_model == CM_HSV)
346
 
    {
347
 
      float r, g, b;
348
 
      float h, s, v;
349
 
      h = m_red->GetValue();
350
 
      s = m_green->GetValue();
351
 
      v = m_blue->GetValue();
352
 
 
353
 
      HSVtoRGB (r, g, b, h, 1.0f, 1.0f);
354
 
 
355
 
      m_red->AddColorMark (0.0f, Color (1.0f, 0.0, 0.0), false);
356
 
      m_red->AddColorMark (1.0f / 6.0f, Color (1.0f, 1.0, 0.0), false);
357
 
      m_red->AddColorMark (2.0f / 6.0f, Color (0.0f, 1.0, 0.0), false);
358
 
      m_red->AddColorMark (3.0f / 6.0f, Color (0.0f, 1.0, 1.0), false);
359
 
      m_red->AddColorMark (4.0f / 6.0f, Color (0.0f, 0.0, 1.0), false);
360
 
      m_red->AddColorMark (5.0f / 6.0f, Color (1.0f, 0.0, 1.0), false);
361
 
      m_red->AddColorMark (1.0f, Color (1.0f, 0.0, 0.0), false);
362
 
 
363
 
      if (h == 1.0f)
364
 
        h = 0.0f;
365
 
 
366
 
      HSVtoRGB (r, g, b, h, 1.0f, 1.0f);
367
 
      m_green->AddColorMark (0, Color (v, v, v), false);
368
 
      m_green->AddColorMark (1.0f, Color (r * v, g * v, b * v), false);
369
 
 
370
 
      HSVtoRGB (r, g, b, h, s, 1.0f);
371
 
      m_blue->AddColorMark (0, Color (0, 0, 0), false);
372
 
      m_blue->AddColorMark (1.0f, Color (r, g, b), false);
373
 
 
374
 
      HSVtoRGB (m_Red, m_Green, m_Blue, h, s, v);
375
 
    }
376
 
 
377
 
    if (m_color_model == CM_HLS)
378
 
    {
379
 
      float r, g, b;
380
 
      float h, l, s;
381
 
      h = m_red->GetValue();
382
 
      l = m_green->GetValue();
383
 
      s = m_blue->GetValue();
384
 
 
385
 
      m_red->AddColorMark (0.0f, Color (1.0f, 0.0, 0.0), false);
386
 
      m_red->AddColorMark (1.0f / 6.0f, Color (1.0f, 1.0, 0.0), false);
387
 
      m_red->AddColorMark (2.0f / 6.0f, Color (0.0f, 1.0, 0.0), false);
388
 
      m_red->AddColorMark (3.0f / 6.0f, Color (0.0f, 1.0, 1.0), false);
389
 
      m_red->AddColorMark (4.0f / 6.0f, Color (0.0f, 0.0, 1.0), false);
390
 
      m_red->AddColorMark (5.0f / 6.0f, Color (1.0f, 0.0, 1.0), false);
391
 
      m_red->AddColorMark (1.0f, Color (1.0f, 0.0, 0.0), false);
392
 
 
393
 
      s = 1.0f - s;
394
 
 
395
 
      if (h == 1.0f)
396
 
        h = 0.0f;
 
302
    if (color_model_ == color::RGB)
 
303
    {
 
304
      color::RedGreenBlue rgb(m_red->GetValue(),
 
305
                              m_green->GetValue(),
 
306
                              m_blue->GetValue());
 
307
 
 
308
      m_red->AddColorMark (0, Color (0.0f, rgb.green, rgb.blue), false);
 
309
      m_red->AddColorMark (1, Color (1.0f, rgb.green, rgb.blue), false);
 
310
      m_green->AddColorMark (0, Color (rgb.red, 0.0f, rgb.blue), false);
 
311
      m_green->AddColorMark (1, Color (rgb.red, 1.0f, rgb.blue), false);
 
312
      m_blue->AddColorMark (0, Color (rgb.red, rgb.green, 0.0f), false);
 
313
      m_blue->AddColorMark (1, Color (rgb.red, rgb.green, 1.0f), false);
 
314
 
 
315
      rgb_values_ = rgb;
 
316
    }
 
317
 
 
318
    if (color_model_ == color::HSV)
 
319
    {
 
320
      color::HueSaturationValue hsv(m_red->GetValue(),
 
321
                                    m_green->GetValue(),
 
322
                                    m_blue->GetValue());
 
323
 
 
324
      m_red->AddColorMark (0.0f, Color (1.0f, 0.0, 0.0), false);
 
325
      m_red->AddColorMark (1.0f / 6.0f, Color (1.0f, 1.0, 0.0), false);
 
326
      m_red->AddColorMark (2.0f / 6.0f, Color (0.0f, 1.0, 0.0), false);
 
327
      m_red->AddColorMark (3.0f / 6.0f, Color (0.0f, 1.0, 1.0), false);
 
328
      m_red->AddColorMark (4.0f / 6.0f, Color (0.0f, 0.0, 1.0), false);
 
329
      m_red->AddColorMark (5.0f / 6.0f, Color (1.0f, 0.0, 1.0), false);
 
330
      m_red->AddColorMark (1.0f, Color (1.0f, 0.0, 0.0), false);
 
331
 
 
332
      if (hsv.hue == 1.0f)
 
333
        hsv.hue = 0.0f;
 
334
 
 
335
      // Save these hsv values as rgb values.
 
336
      rgb_values_ = color::RedGreenBlue(hsv);
 
337
 
 
338
      // The green holds the saturation.
 
339
      Color min_green(hsv.value, hsv.value, hsv.value);
 
340
 
 
341
      // The blue slider handles full value.
 
342
      hsv.value = 1.0f;
 
343
      color::RedGreenBlue blue_slider(hsv);
 
344
      m_blue->AddColorMark (0, color::Black, false);
 
345
      m_blue->AddColorMark (1.0f, Color(blue_slider), false);
 
346
 
 
347
      // Max green slider has full saturation and value
 
348
      hsv.saturation = 1.0f;
 
349
      color::RedGreenBlue green_slider(hsv);
 
350
      Color max_green = Color(green_slider) * hsv.value;
 
351
      m_green->AddColorMark (0, min_green, false);
 
352
      m_green->AddColorMark (1.0f, max_green, false);
 
353
    }
 
354
 
 
355
    if (color_model_ == color::HLS)
 
356
    {
 
357
      color::HueLightnessSaturation hls(m_red->GetValue(),
 
358
                                        m_green->GetValue(),
 
359
                                        m_blue->GetValue());
 
360
      m_red->AddColorMark (0.0f, Color (1.0f, 0.0, 0.0), false);
 
361
      m_red->AddColorMark (1.0f / 6.0f, Color (1.0f, 1.0, 0.0), false);
 
362
      m_red->AddColorMark (2.0f / 6.0f, Color (0.0f, 1.0, 0.0), false);
 
363
      m_red->AddColorMark (3.0f / 6.0f, Color (0.0f, 1.0, 1.0), false);
 
364
      m_red->AddColorMark (4.0f / 6.0f, Color (0.0f, 0.0, 1.0), false);
 
365
      m_red->AddColorMark (5.0f / 6.0f, Color (1.0f, 0.0, 1.0), false);
 
366
      m_red->AddColorMark (1.0f, Color (1.0f, 0.0, 0.0), false);
 
367
 
 
368
      // Save these hsv values as rgb values.
 
369
      if (hls.hue == 1.0f)
 
370
        hls.hue = 0.0f;
 
371
 
 
372
      rgb_values_ = color::RedGreenBlue(hls);
 
373
 
 
374
      float s = (1.0f - hls.saturation) * 0.5;
397
375
 
398
376
      // Need to use HSVtoRGB to compute the primary color
399
 
      HSVtoRGB (r, g, b, h, 1.0f, 1.0f);
400
 
      m_green->AddColorMark (0.0f, Color (0, 0, 0), false);
401
 
      m_green->AddColorMark (0.5f, Color (r* (1 - s) + 0.5f * s, g* (1 - s) + 0.5f * s, b* (1 - s) + 0.5f * s), false);
402
 
      m_green->AddColorMark (1.0f, Color (1.0f, 1.0f, 1.0f), false);
403
 
 
404
 
      float cr, cg, cb;
405
 
 
406
 
      if (l > 0.5)
 
377
      color::HueSaturationValue primary_hsv(hls.hue, 1.0f, 1.0f);
 
378
      color::RedGreenBlue primary_rgb(primary_hsv);
 
379
      Color primary = Color(primary_rgb) * hls.saturation + s;
 
380
      m_green->AddColorMark (0.0f, color::Black, false);
 
381
      m_green->AddColorMark (0.5f, primary, false);
 
382
      m_green->AddColorMark (1.0f, color::White, false);
 
383
 
 
384
      // Not sure on the name of this color...
 
385
      Color secondary = Color(primary_rgb);
 
386
 
 
387
      if (hls.lightness > 0.5)
407
388
      {
408
 
        float factor = (l - 0.5f) / 0.5f;
409
 
        cr = (1 - factor) * r * (1 - s) + 0.5 * s + factor * 1.0f;
410
 
        cg = (1 - factor) * g * (1 - s) + 0.5 * s + factor * 1.0f;
411
 
        cb = (1 - factor) * b * (1 - s) + 0.5 * s + factor * 1.0f;
 
389
        float factor = (hls.lightness - 0.5f) / 0.5f;
 
390
        secondary = secondary * ((1 - factor) * hls.saturation) + (s + factor);
412
391
      }
413
392
      else
414
393
      {
415
 
        float factor = l / 0.5f;
416
 
        cr = (factor) * r * (1 - s) + 0.5 * s;
417
 
        cg = (factor) * g * (1 - s) + 0.5 * s;
418
 
        cb = (factor) * b * (1 - s) + 0.5 * s;
 
394
        float factor = hls.lightness / 0.5f * hls.saturation;
 
395
        secondary = secondary * factor + s;
419
396
      }
420
397
 
421
 
      m_blue->AddColorMark (0, Color (l, l, l), false);
422
 
      m_blue->AddColorMark (1.0f, Color (cr, cg, cb), false);
423
 
 
424
 
      HLStoRGB (m_Red, m_Green, m_Blue, h, l, 1.0f - s);
 
398
      m_blue->AddColorMark (0, Color (hls.lightness, hls.lightness, hls.lightness), false);
 
399
      m_blue->AddColorMark (1.0f, secondary, false);
425
400
    }
426
401
  }
427
402
 
451
426
    TiXmlElement *childxml;
452
427
    childxml = new TiXmlElement (TEXT ("RGBComponent") );
453
428
    //childxml->SetAttribute(TEXT("Name"), m_X->GetName());
454
 
    childxml->SetDoubleAttribute (TEXT ("Red"), (double) m_Red);
 
429
    childxml->SetDoubleAttribute (TEXT ("Red"), rgb_values_.red);
455
430
    elementxml->LinkEndChild (childxml);
456
431
    childxml = new TiXmlElement (TEXT ("RGBComponent") );
457
432
    //childxml->SetAttribute(TEXT("Name"), m_Y->GetName());
458
 
    childxml->SetDoubleAttribute (TEXT ("Green"), (double) m_Green);
 
433
    childxml->SetDoubleAttribute (TEXT ("Green"), rgb_values_.green);
459
434
    elementxml->LinkEndChild (childxml);
460
435
    childxml = new TiXmlElement (TEXT ("RGBComponent") );
461
436
    //childxml->SetAttribute(TEXT("Name"), m_Z->GetName());
462
 
    childxml->SetDoubleAttribute (TEXT ("Blue"), (double) m_Blue);
 
437
    childxml->SetDoubleAttribute (TEXT ("Blue"), rgb_values_.blue);
463
438
    elementxml->LinkEndChild (childxml);
464
439
 
465
440
    return elementxml;