~didrocks/unity/launcher-bug-fix-fest

« back to all changes in this revision

Viewing changes to src/Tooltip.cpp

Import the work done so far with Compiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "Nux/Nux.h"
 
2
#include "Nux/VLayout.h"
 
3
#include "Nux/HLayout.h"
 
4
#include "Nux/WindowThread.h"
 
5
#include "Nux/WindowCompositor.h"
 
6
#include "Nux/BaseWindow.h"
 
7
#include "Nux/Button.h"
 
8
#include "NuxGraphics/OpenGLEngine.h"
 
9
#include "NuxGraphics/GfxEventsX11.h"
 
10
#include "NuxGraphics/GfxSetupX11.h"
 
11
#include "Nux/TextureArea.h"
 
12
#include "NuxImage/CairoGraphics.h"
 
13
 
 
14
#include "Tooltip.h"
 
15
 
 
16
namespace nux
 
17
{
 
18
  NUX_IMPLEMENT_OBJECT_TYPE (Tooltip);
 
19
  
 
20
  void
 
21
  DrawCairo (cairo_t* cr,
 
22
             gboolean outline,
 
23
             gfloat   line_width,
 
24
             gfloat*  rgba,
 
25
             gboolean negative,
 
26
             gboolean stroke)
 
27
  {
 
28
    // prepare drawing
 
29
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
 
30
 
 
31
    // actually draw the mask
 
32
    if (outline)
 
33
      {
 
34
        cairo_set_line_width (cr, line_width);
 
35
        cairo_set_source_rgba (cr, rgba[0], rgba[1], rgba[2], rgba[3]);
 
36
      }
 
37
    else
 
38
      {
 
39
        if (negative)
 
40
          cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
 
41
        else
 
42
          cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
 
43
      }
 
44
 
 
45
    // stroke or fill?
 
46
    if (stroke)
 
47
      cairo_stroke_preserve (cr);
 
48
    else
 
49
      cairo_fill_preserve (cr);
 
50
  }
 
51
 
 
52
  void
 
53
  nux::Tooltip::ComputeFullMaskPath (cairo_t* cr,
 
54
                                gfloat   anchor_width,
 
55
                                gfloat   anchor_height,
 
56
                                gint     width,
 
57
                                gint     height,
 
58
                                gint     upper_size,
 
59
                                gfloat   radius,
 
60
                                guint    pad)
 
61
  {
 
62
    //     0  1        2  3
 
63
    //     +--+--------+--+
 
64
    //     |              |
 
65
    //     + 14           + 4
 
66
    //     |              |
 
67
    //     |              |
 
68
    //     |              |
 
69
    //     + 13           |
 
70
    //    /               |
 
71
    //   /                |
 
72
    //  + 12              |
 
73
    //   \                |
 
74
    //    \               |
 
75
    //  11 +              |
 
76
    //     |              |
 
77
    //     |              |
 
78
    //     |              |
 
79
    //  10 +              + 5
 
80
    //     |              |
 
81
    //     +--+--------+--+ 6
 
82
    //     9  8        7
 
83
 
 
84
    gfloat padding    = pad;
 
85
    float  ZEROPOINT5 = 0.5f;
 
86
  
 
87
    gfloat HeightToAnchor = 0.0f;
 
88
    HeightToAnchor = ((gfloat) height - 2.0f * radius - anchor_height -2*padding) / 2.0f;
 
89
    if (HeightToAnchor < 0.0f)
 
90
    {
 
91
      g_warning ("Anchor-height and corner-radius a higher than whole texture!");
 
92
      return;
 
93
    }
 
94
 
 
95
    //gint dynamic_size = height - 2*radius - 2*padding - anchor_height;
 
96
    //gint upper_dynamic_size = upper_size;
 
97
    //gint lower_dynamic_size = dynamic_size - upper_dynamic_size;
 
98
  
 
99
    if (upper_size >= 0)
 
100
      {
 
101
        if(upper_size > height - 2.0f * radius - anchor_height -2 * padding)
 
102
          {
 
103
            //g_warning ("[_compute_full_mask_path] incorrect upper_size value");
 
104
            HeightToAnchor = 0;
 
105
          }
 
106
        else
 
107
          {
 
108
            HeightToAnchor = height - 2.0f * radius - anchor_height -2 * padding - upper_size;
 
109
          }
 
110
      }
 
111
    else
 
112
      {
 
113
        HeightToAnchor = (height - 2.0f * radius - anchor_height -2*padding) / 2.0f;
 
114
      }
 
115
 
 
116
    cairo_translate (cr, -0.5f, -0.5f);
 
117
    
 
118
    // create path
 
119
    cairo_move_to (cr, padding + anchor_width + radius + ZEROPOINT5, padding + ZEROPOINT5); // Point 1
 
120
    cairo_line_to (cr, width - padding - radius, padding + ZEROPOINT5);   // Point 2
 
121
    cairo_arc (cr,
 
122
               width  - padding - radius + ZEROPOINT5,
 
123
               padding + radius + ZEROPOINT5,
 
124
               radius,
 
125
               -90.0f * G_PI / 180.0f,
 
126
               0.0f * G_PI / 180.0f);   // Point 4
 
127
    cairo_line_to (cr,
 
128
                   (gdouble) width - padding + ZEROPOINT5,
 
129
                   (gdouble) height - radius - padding + ZEROPOINT5); // Point 5
 
130
    cairo_arc (cr,
 
131
               (gdouble) width - padding - radius + ZEROPOINT5,
 
132
               (gdouble) height - padding - radius + ZEROPOINT5,
 
133
               radius,
 
134
               0.0f * G_PI / 180.0f,
 
135
               90.0f * G_PI / 180.0f);  // Point 7
 
136
    cairo_line_to (cr,
 
137
                   anchor_width + padding + radius + ZEROPOINT5,
 
138
                   (gdouble) height - padding + ZEROPOINT5); // Point 8
 
139
 
 
140
    cairo_arc (cr,
 
141
               anchor_width + padding + radius + ZEROPOINT5,
 
142
               (gdouble) height - padding - radius,
 
143
               radius,
 
144
               90.0f * G_PI / 180.0f,
 
145
               180.0f * G_PI / 180.0f); // Point 10
 
146
 
 
147
    cairo_line_to (cr,
 
148
                   padding + anchor_width + ZEROPOINT5,
 
149
                   (gdouble) height - padding - radius - HeightToAnchor + ZEROPOINT5 );  // Point 11
 
150
    cairo_line_to (cr,
 
151
                   padding + ZEROPOINT5,
 
152
                   (gdouble) height - padding - radius - HeightToAnchor - anchor_height / 2.0f + ZEROPOINT5); // Point 12
 
153
    cairo_line_to (cr,
 
154
                   padding + anchor_width + ZEROPOINT5,
 
155
                   (gdouble) height - padding - radius - HeightToAnchor - anchor_height + ZEROPOINT5);  // Point 13
 
156
  
 
157
    cairo_line_to (cr, padding + anchor_width + ZEROPOINT5, 
 
158
                   padding + radius  + ZEROPOINT5);  // Point 14
 
159
    cairo_arc (cr,
 
160
               padding + anchor_width + radius + ZEROPOINT5,
 
161
               padding + radius + ZEROPOINT5,
 
162
               radius,
 
163
               180.0f * G_PI / 180.0f,
 
164
               270.0f * G_PI / 180.0f);
 
165
 
 
166
    cairo_close_path (cr);
 
167
  }
 
168
 
 
169
  void
 
170
  ComputeMask (cairo_t* cr)
 
171
  {
 
172
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
 
173
    cairo_fill_preserve (cr);
 
174
  }
 
175
 
 
176
  void
 
177
  nux::Tooltip::ComputeOutline (cairo_t* cr,
 
178
                           gfloat   line_width,
 
179
                           gfloat*  rgba_line,
 
180
                           gint     width,
 
181
                           gfloat   anchor_width,
 
182
                           gfloat   corner_radius,
 
183
                           gint     padding_size)
 
184
  {
 
185
    cairo_pattern_t* pattern = NULL;
 
186
    double           offset  = 0.0;
 
187
 
 
188
    if (width == 0)
 
189
    {
 
190
      g_warning ("%s(): passed in width is 0!", G_STRFUNC);
 
191
      return;
 
192
    }
 
193
 
 
194
    offset = ((double) padding_size + anchor_width) / (double) width;
 
195
 
 
196
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
 
197
    cairo_set_line_width (cr, line_width);
 
198
 
 
199
    pattern = cairo_pattern_create_linear (0.0, 0.0, (double) width, 0.0);
 
200
    cairo_pattern_add_color_stop_rgba (pattern,
 
201
                                       0.0,
 
202
                                       rgba_line[0],
 
203
                                       rgba_line[1],
 
204
                                       rgba_line[2],
 
205
                                       0.9);
 
206
    cairo_pattern_add_color_stop_rgba (pattern,
 
207
                                       offset,
 
208
                                       rgba_line[0],
 
209
                                       rgba_line[1],
 
210
                                       rgba_line[2],
 
211
                                       0.9);
 
212
    cairo_pattern_add_color_stop_rgba (pattern,
 
213
                                       offset + 0.0125,
 
214
                                       rgba_line[0],
 
215
                                       rgba_line[1],
 
216
                                       rgba_line[2],
 
217
                                       0.6);
 
218
    cairo_pattern_add_color_stop_rgba (pattern,
 
219
                                       1.0,
 
220
                                       rgba_line[0],
 
221
                                       rgba_line[1],
 
222
                                       rgba_line[2],
 
223
                                       0.6);
 
224
 
 
225
    cairo_set_source (cr, pattern);
 
226
    cairo_stroke (cr);
 
227
    cairo_pattern_destroy (pattern);
 
228
  }
 
229
 
 
230
  void
 
231
  Tooltip::DrawTintDotHighlight (cairo_t* cr,
 
232
                                      gint     width,
 
233
                                      gint     height,
 
234
                                      gfloat   hl_x,
 
235
                                      gfloat   hl_y,
 
236
                                      gfloat   hl_size,
 
237
                                      gfloat*  rgba_tint,
 
238
                                      gfloat*  rgba_hl)
 
239
  {
 
240
    cairo_surface_t* dots_surf    = NULL;
 
241
    cairo_t*         dots_cr      = NULL;
 
242
    cairo_pattern_t* dots_pattern = NULL;
 
243
    cairo_pattern_t* hl_pattern   = NULL;
 
244
 
 
245
    // create context for dot-pattern
 
246
    dots_surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 4, 4);
 
247
    dots_cr = cairo_create (dots_surf);
 
248
 
 
249
    // clear normal context
 
250
    cairo_scale (cr, 1.0f, 1.0f);
 
251
    cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
 
252
    cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
 
253
    cairo_paint (cr);
 
254
 
 
255
    // prepare drawing for normal context
 
256
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
257
 
 
258
    // create path in normal context
 
259
    ComputeFullMaskPath (cr,
 
260
                         ANCHOR_WIDTH,
 
261
                         ANCHOR_HEIGHT,
 
262
                         width,
 
263
                         height,
 
264
                         -1,
 
265
                         RADIUS,
 
266
                         PADDING_SIZE);
 
267
    //cairo_rectangle (cr, 0.0f, 0.0f, (gdouble) width, (gdouble) height);  
 
268
 
 
269
    // fill path of normal context with tint
 
270
    cairo_set_source_rgba (cr,
 
271
                           rgba_tint[0],
 
272
                           rgba_tint[1],
 
273
                           rgba_tint[2],
 
274
                           rgba_tint[3]);
 
275
    cairo_fill_preserve (cr);
 
276
 
 
277
    // create pattern in dot-context
 
278
    cairo_set_operator (dots_cr, CAIRO_OPERATOR_CLEAR);
 
279
    cairo_paint (dots_cr);
 
280
    cairo_scale (dots_cr, 1.0f, 1.0f);
 
281
    cairo_set_operator (dots_cr, CAIRO_OPERATOR_OVER);
 
282
    cairo_set_source_rgba (dots_cr,
 
283
                           rgba_hl[0],
 
284
                           rgba_hl[1],
 
285
                           rgba_hl[2],
 
286
                           rgba_hl[3]);
 
287
    cairo_rectangle (dots_cr, 0.0f, 0.0f, 1.0f, 1.0f);
 
288
    cairo_fill (dots_cr);
 
289
    cairo_rectangle (dots_cr, 2.0f, 2.0f, 1.0f, 1.0f);
 
290
    cairo_fill (dots_cr);
 
291
 
 
292
    dots_pattern = cairo_pattern_create_for_surface (dots_surf);
 
293
 
 
294
    // fill path of normal context with dot-pattern
 
295
    // FIXME: using the path from ComputeFullMaskPath() and not a plain rect.
 
296
    // path triggers a bug in cairo (yet to be filed), so repeating of the dot-
 
297
    // pattern produces wrong pattern in the end, a viable work-around still
 
298
    // needs to be thought up
 
299
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
300
    cairo_set_source (cr, dots_pattern);
 
301
    cairo_pattern_set_extend (dots_pattern, CAIRO_EXTEND_REPEAT);
 
302
    cairo_fill_preserve (cr);
 
303
    cairo_pattern_destroy (dots_pattern);
 
304
    cairo_surface_destroy (dots_surf);
 
305
    cairo_destroy (dots_cr);
 
306
 
 
307
    // draw highlight
 
308
    cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
309
    hl_pattern = cairo_pattern_create_radial (hl_x,
 
310
                                              hl_y,
 
311
                                              0.0f,
 
312
                                              hl_x,
 
313
                                              hl_y,
 
314
                                              hl_size);
 
315
    cairo_pattern_add_color_stop_rgba (hl_pattern,
 
316
                                       0.0f,
 
317
                                       1.0f,
 
318
                                       1.0f,
 
319
                                       1.0f,
 
320
                                       0.75f);
 
321
    cairo_pattern_add_color_stop_rgba (hl_pattern,
 
322
                                       1.0f,
 
323
                                       1.0f,
 
324
                                       1.0f,
 
325
                                       1.0f,
 
326
                                       0.0f);
 
327
    cairo_set_source (cr, hl_pattern);
 
328
    cairo_fill (cr);
 
329
    cairo_pattern_destroy (hl_pattern);
 
330
  }
 
331
 
 
332
  void
 
333
  Tooltip::DrawMask (cairo_t* cr,
 
334
                          gint     width,
 
335
                          gint     height,
 
336
                          gfloat   radius,
 
337
                          guint    shadow_radius,
 
338
                          gfloat   anchor_width,
 
339
                          gfloat   anchor_height,
 
340
                          gint     upper_size,
 
341
                          gboolean negative,
 
342
                          gboolean outline,
 
343
                          gfloat   line_width,
 
344
                          gint     padding_size,
 
345
                          gfloat*  rgba)
 
346
  {
 
347
    ComputeFullMaskPath (cr,
 
348
                         anchor_width,
 
349
                         anchor_height,
 
350
                         width,
 
351
                         height,
 
352
                         upper_size,
 
353
                         radius,
 
354
                         padding_size);
 
355
  }
 
356
 
 
357
  void
 
358
  Tooltip::GetDPI ()
 
359
  {
 
360
#if defined(NUX_OS_LINUX)
 
361
    Display* display     = NULL;
 
362
    int      screen      = 0;
 
363
    double   dpyWidth    = 0.0;
 
364
    double   dpyHeight   = 0.0;
 
365
    double   dpyWidthMM  = 0.0;
 
366
    double   dpyHeightMM = 0.0;
 
367
    double   dpiX        = 0.0;
 
368
    double   dpiY        = 0.0;
 
369
 
 
370
    display = XOpenDisplay (NULL);
 
371
    screen = DefaultScreen (display);
 
372
 
 
373
    dpyWidth    = (double) DisplayWidth (display, screen);
 
374
    dpyHeight   = (double) DisplayHeight (display, screen);
 
375
    dpyWidthMM  = (double) DisplayWidthMM (display, screen);
 
376
    dpyHeightMM = (double) DisplayHeightMM (display, screen);
 
377
 
 
378
    dpiX = dpyWidth * 25.4 / dpyWidthMM;
 
379
    dpiY = dpyHeight * 25.4 / dpyHeightMM;
 
380
 
 
381
    _dpiX = (int) (dpiX + 0.5);
 
382
    _dpiY = (int) (dpiY + 0.5);
 
383
 
 
384
    XCloseDisplay (display);
 
385
#elif defined(NUX_OS_WINDOWS)
 
386
    _dpiX = 72;
 
387
    _dpiY = 72;
 
388
#endif
 
389
  }
 
390
 
 
391
  void
 
392
  Tooltip::GetTextExtents (char* font,
 
393
                                int*  width,
 
394
                                int*  height)
 
395
  {
 
396
    cairo_surface_t*      surface  = NULL;
 
397
    cairo_t*              cr       = NULL;
 
398
    PangoLayout*          layout   = NULL;
 
399
    PangoFontDescription* desc     = NULL;
 
400
    PangoContext*         pangoCtx = NULL;
 
401
    PangoRectangle        logRect  = {0, 0, 0, 0};
 
402
 
 
403
    // sanity check
 
404
    if (!font || !width || !height)
 
405
      return;
 
406
 
 
407
    surface = cairo_image_surface_create (CAIRO_FORMAT_A1, 1, 1);
 
408
    cr = cairo_create (surface);
 
409
    layout = pango_cairo_create_layout (cr);
 
410
    desc = pango_font_description_from_string (font);
 
411
    pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL);
 
412
    pango_layout_set_font_description (layout, desc);
 
413
    pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
 
414
    pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
 
415
    pango_layout_set_text (layout, _labelText.GetTCharPtr(), -1);
 
416
    pangoCtx = pango_layout_get_context (layout); // is not ref'ed
 
417
    pango_cairo_context_set_font_options (pangoCtx, _fontOpts);
 
418
    pango_cairo_context_set_resolution (pangoCtx, _dpiX);
 
419
    pango_layout_context_changed (layout);
 
420
    pango_layout_get_extents (layout, NULL, &logRect);
 
421
 
 
422
    *width  = logRect.width / PANGO_SCALE;
 
423
    *height = logRect.height / PANGO_SCALE;
 
424
 
 
425
    // clean up
 
426
    pango_font_description_free (desc);
 
427
    g_object_unref (layout);
 
428
    cairo_destroy (cr);
 
429
    cairo_surface_destroy (surface);
 
430
  }
 
431
 
 
432
  void
 
433
  Tooltip::DrawLabel (cairo_t* cr,
 
434
                      gint     width,
 
435
                      gint     height,
 
436
                      gfloat*  rgba)
 
437
  {
 
438
    int                   textWidth  = 0;
 
439
    int                   textHeight = 0;
 
440
    PangoLayout*          layout     = NULL;
 
441
    PangoFontDescription* desc       = NULL;
 
442
    PangoContext*         pangoCtx   = NULL;
 
443
 
 
444
    GetTextExtents ((char*) FONT_FACE,
 
445
                    &textWidth,
 
446
                    &textHeight);
 
447
 
 
448
    cairo_set_source_rgba (cr, rgba[0], rgba[1], rgba[2], rgba[3]);
 
449
 
 
450
    cairo_set_font_options (cr, _fontOpts);
 
451
    layout = pango_cairo_create_layout (cr);
 
452
    desc = pango_font_description_from_string ((char*) FONT_FACE);
 
453
    pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL);
 
454
    pango_layout_set_font_description (layout, desc);
 
455
    pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
 
456
    pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
 
457
    pango_layout_set_text (layout, _labelText.GetTCharPtr(), -1);
 
458
    pangoCtx = pango_layout_get_context (layout); // is not ref'ed
 
459
    pango_cairo_context_set_font_options (pangoCtx, _fontOpts);
 
460
    pango_cairo_context_set_resolution (pangoCtx, (double) _dpiX);
 
461
    pango_layout_context_changed (layout);
 
462
 
 
463
    cairo_move_to (cr,
 
464
                   ANCHOR_WIDTH + (float) ((width - ANCHOR_WIDTH) - textWidth) / 2.0f,
 
465
                   (float) (height - textHeight) / 2.0f);
 
466
    pango_cairo_show_layout (cr, layout);
 
467
    cairo_fill (cr);
 
468
 
 
469
    // clean up
 
470
    pango_font_description_free (desc);
 
471
    g_object_unref (layout);
 
472
  }
 
473
 
 
474
  void
 
475
  Tooltip::DrawOutlineShadow (cairo_t* cr,
 
476
                                   gint     width,
 
477
                                   gint     height,
 
478
                                   gfloat   anchor_width,
 
479
                                   gfloat   anchor_height,
 
480
                                   gint     upper_size,
 
481
                                   gfloat   corner_radius,
 
482
                                   guint    blur_coeff,
 
483
                                   gfloat*  rgba_shadow,
 
484
                                   gfloat   line_width,
 
485
                                   gint     padding_size,
 
486
                                   gfloat*  rgba_line)
 
487
  {
 
488
    ComputeFullMaskPath (cr,
 
489
                         anchor_width,
 
490
                         anchor_height,
 
491
                         width,
 
492
                         height,
 
493
                         upper_size,
 
494
                         corner_radius,
 
495
                         padding_size);
 
496
    //DrawCairo (cr, TRUE, line_width, rgba_shadow, FALSE, FALSE);
 
497
    //ctk_surface_blur (surf, blur_coeff);
 
498
    //ComputeMask (cr);
 
499
    ComputeOutline (cr,
 
500
                    line_width,
 
501
                    rgba_line,
 
502
                    width,
 
503
                    anchor_width,
 
504
                    corner_radius,
 
505
                    padding_size);
 
506
  }
 
507
 
 
508
  Tooltip::Tooltip ()
 
509
  {
 
510
    _anchorX   = 0;
 
511
    _anchorY   = 0;
 
512
    _labelText = TEXT ("unset");
 
513
    _fontOpts  = cairo_font_options_create ();
 
514
 
 
515
    // FIXME: hard-coding these for the moment, as we don't have
 
516
    // gsettings-support in place right now
 
517
    cairo_font_options_set_antialias (_fontOpts, CAIRO_ANTIALIAS_SUBPIXEL);
 
518
    cairo_font_options_set_hint_metrics (_fontOpts, CAIRO_HINT_METRICS_ON);
 
519
    cairo_font_options_set_hint_style (_fontOpts, CAIRO_HINT_STYLE_SLIGHT);
 
520
    cairo_font_options_set_subpixel_order (_fontOpts, CAIRO_SUBPIXEL_ORDER_RGB);
 
521
 
 
522
    // make sure _dpiX and _dpiY are initialized correctly
 
523
    GetDPI ();
 
524
  }
 
525
 
 
526
  Tooltip::~Tooltip ()
 
527
  {
 
528
    cairo_font_options_destroy (_fontOpts);
 
529
    delete(_cairo_graphics);
 
530
    delete(_texture2D);
 
531
  }
 
532
 
 
533
  long
 
534
  Tooltip::ProcessEvent (IEvent& ievent,
 
535
                         long    TraverseInfo,
 
536
                         long    ProcessEventInfo)
 
537
  {
 
538
    return TraverseInfo;
 
539
  }
 
540
 
 
541
  void
 
542
  Tooltip::Draw (GraphicsContext& gfxContext,
 
543
                 bool             forceDraw)
 
544
  {
 
545
    Geometry base = GetGeometry();
 
546
 
 
547
    // the elements position inside the window are referenced to top-left window
 
548
    // corner. So bring base to (0, 0).
 
549
    base.SetX (0);
 
550
    base.SetY (0);
 
551
    gfxContext.PushClippingRectangle (base);
 
552
 
 
553
    gPainter.PushDrawShapeLayer (gfxContext,
 
554
                                 base,
 
555
                                 eSHAPE_CORNER_ROUND10,
 
556
                                 m_background_color, eAllCorners, true);
 
557
 
 
558
    TexCoordXForm texxform;
 
559
    texxform.SetWrap(TEXWRAP_REPEAT, TEXWRAP_REPEAT);
 
560
    texxform.SetTexCoordType (TexCoordXForm::OFFSET_COORD);
 
561
 
 
562
    gfxContext.QRP_GLSL_1Tex (base.x,
 
563
                              base.y,
 
564
                              base.width,
 
565
                              base.height,
 
566
                              _texture2D->GetDeviceTexture(),
 
567
                              texxform,
 
568
                              Color(1.0f, 1.0f, 1.0f, 1.0f));
 
569
 
 
570
    gPainter.PopBackground ();
 
571
    gfxContext.PopClippingRectangle ();
 
572
  }
 
573
 
 
574
  void
 
575
  Tooltip::DrawContent (GraphicsContext& GfxContext,
 
576
                             bool             force_draw)
 
577
  {
 
578
    /*Geometry base = GetGeometry();
 
579
    int x = base.x;
 
580
    int y = base.y;
 
581
    // The elements position inside the window are referenced to top-left window corner. So bring base to (0, 0).
 
582
    base.SetX (0);
 
583
    base.SetY (0);
 
584
 
 
585
    if (UseBlurredBackground() )
 
586
    {
 
587
      TexCoordXForm texxform;
 
588
      texxform.uoffset = (float) x / (float) GetThreadWindowCompositor().GetScreenBlurTexture()->GetWidth();
 
589
      texxform.voffset = (float) y / (float) GetThreadWindowCompositor().GetScreenBlurTexture()->GetHeight();
 
590
      texxform.SetTexCoordType (TexCoordXForm::OFFSET_COORD);
 
591
 
 
592
      gPainter.PushTextureLayer (GfxContext, base, GetThreadWindowCompositor().GetScreenBlurTexture(), texxform, Color::White, true);
 
593
    }
 
594
    else
 
595
    {
 
596
      //nuxDebugMsg(TEXT("[BaseWindow::DrawContent]"));
 
597
      gPainter.PushShapeLayer (GfxContext, base, eSHAPE_CORNER_ROUND10, m_background_color, eAllCorners, true);
 
598
      //GfxContext.QRP_GLSL_Color(base.x, base.y, base.width, base.height, Color(1.0f, 0.0f, 0.0f, 1.0f));
 
599
      //GfxContext.QRP_GLSL_Color(base.x, base.y, base.width, base.height, Color(1.0f / (float) (std::rand () % 100), 1.0f / (float) (std::rand () % 100), 1.0f / (float) (std::rand () % 100), 0.5f));
 
600
    }
 
601
 
 
602
    if (m_layout)
 
603
    {
 
604
      GfxContext.PushClippingRectangle (base);
 
605
      m_layout->ProcessDraw (GfxContext, force_draw);
 
606
      GfxContext.PopClippingRectangle();
 
607
    }
 
608
 
 
609
    gPainter.PopBackground();*/
 
610
  }
 
611
 
 
612
  void Tooltip::PreLayoutManagement ()
 
613
  {
 
614
    int  newWidth   = 0;
 
615
    int  newHeight  = 0;
 
616
    int  textWidth  = 0;
 
617
    int  textHeight = 0;
 
618
 
 
619
    GetTextExtents ((char*) FONT_FACE,
 
620
                    &textWidth,
 
621
                    &textHeight);
 
622
 
 
623
    newWidth = textWidth + 2 * H_MARGIN + ANCHOR_WIDTH + 2 * PADDING_SIZE;
 
624
    newHeight = textHeight + 2 * V_MARGIN + 2 * PADDING_SIZE;
 
625
    SetBaseSize (newWidth, newHeight);
 
626
 
 
627
    UpdateTexture ();
 
628
 
 
629
    BaseWindow::PreLayoutManagement ();
 
630
  }
 
631
 
 
632
  void
 
633
  Tooltip::UpdateTexture ()
 
634
  {
 
635
    float rgbaTint[4]      = {0.0f, 0.0f, 0.0f, 0.7f};
 
636
    float rgbaHighlight[4] = {1.0f, 1.0f, 1.0f, 0.15f};
 
637
    float rgbaLine[4]      = {1.0f, 1.0f, 1.0f, 0.75f};
 
638
    float rgbaShadow[4]    = {0.0f, 0.0f, 0.0f, 0.48f};
 
639
    float rgbaText[4]      = {1.0f, 1.0f, 1.0f, 1.0f};
 
640
    float highLightY       = 0.0f;
 
641
    float highLightW       = 0.0f;
 
642
 
 
643
    _cairo_graphics = new CairoGraphics (CAIRO_FORMAT_ARGB32,
 
644
                                         GetBaseWidth (),
 
645
                                         GetBaseHeight ());
 
646
    cairo_t *cr = _cairo_graphics->GetContext ();
 
647
 
 
648
    highLightY = HIGH_LIGHT_Y;
 
649
    if (GetBaseWidth () / 1.5f < HIGH_LIGHT_MIN_WIDTH)
 
650
        highLightW = HIGH_LIGHT_MIN_WIDTH;
 
651
    else
 
652
        highLightW = GetBaseWidth () / 1.5f;
 
653
 
 
654
    DrawTintDotHighlight (cr,
 
655
                          GetBaseWidth (),
 
656
                          GetBaseHeight (),
 
657
                          GetBaseWidth () / 2.0f,
 
658
                          highLightY,
 
659
                          highLightW,
 
660
                          rgbaTint,
 
661
                          rgbaHighlight);
 
662
 
 
663
    DrawOutlineShadow (cr,
 
664
                       GetBaseWidth (),
 
665
                       GetBaseHeight (),
 
666
                       ANCHOR_WIDTH,
 
667
                       ANCHOR_HEIGHT,
 
668
                       -1,
 
669
                       RADIUS,
 
670
                       BLUR_INTENSITY,
 
671
                       rgbaShadow,
 
672
                       LINE_WIDTH,
 
673
                       PADDING_SIZE,
 
674
                       rgbaLine);
 
675
 
 
676
    DrawLabel (cr,
 
677
               GetBaseWidth (),
 
678
               GetBaseHeight (),
 
679
               rgbaText);
 
680
 
 
681
    NBitmapData* bitmap =  _cairo_graphics->GetBitmap();
 
682
 
 
683
    // BaseTexture is the high level representation of an image that is backed by
 
684
    // an actual opengl texture.
 
685
    _texture2D = GetThreadGLDeviceFactory()->CreateSystemCapableTexture ();
 
686
    _texture2D->Update(bitmap);
 
687
    
 
688
    delete _cairo_graphics;
 
689
  }
 
690
 
 
691
  long
 
692
  Tooltip::PostLayoutManagement (long LayoutResult)
 
693
  {
 
694
    long result = BaseWindow::PostLayoutManagement (LayoutResult);
 
695
 
 
696
    return result;
 
697
  }
 
698
 
 
699
  void
 
700
  Tooltip::PositionChildLayout (float offsetX,
 
701
                                float offsetY)
 
702
  {
 
703
  }
 
704
 
 
705
  void
 
706
  Tooltip::LayoutWindowElements ()
 
707
  {
 
708
  }
 
709
 
 
710
  void
 
711
  Tooltip::NotifyConfigurationChange (int width,
 
712
                                      int height)
 
713
  {
 
714
  }
 
715
 
 
716
  void
 
717
  Tooltip::SetText (NString text)
 
718
  {
 
719
    if (_labelText == text)
 
720
      return;
 
721
 
 
722
    _labelText = text;
 
723
    UpdateTexture ();
 
724
  }
 
725
 
 
726
} // namespace nux
 
727