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"
18
NUX_IMPLEMENT_OBJECT_TYPE (Tooltip);
21
DrawCairo (cairo_t* cr,
29
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
31
// actually draw the mask
34
cairo_set_line_width (cr, line_width);
35
cairo_set_source_rgba (cr, rgba[0], rgba[1], rgba[2], rgba[3]);
40
cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
42
cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
47
cairo_stroke_preserve (cr);
49
cairo_fill_preserve (cr);
53
nux::Tooltip::ComputeFullMaskPath (cairo_t* cr,
85
float ZEROPOINT5 = 0.5f;
87
gfloat HeightToAnchor = 0.0f;
88
HeightToAnchor = ((gfloat) height - 2.0f * radius - anchor_height -2*padding) / 2.0f;
89
if (HeightToAnchor < 0.0f)
91
g_warning ("Anchor-height and corner-radius a higher than whole texture!");
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;
101
if(upper_size > height - 2.0f * radius - anchor_height -2 * padding)
103
//g_warning ("[_compute_full_mask_path] incorrect upper_size value");
108
HeightToAnchor = height - 2.0f * radius - anchor_height -2 * padding - upper_size;
113
HeightToAnchor = (height - 2.0f * radius - anchor_height -2*padding) / 2.0f;
116
cairo_translate (cr, -0.5f, -0.5f);
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
122
width - padding - radius + ZEROPOINT5,
123
padding + radius + ZEROPOINT5,
125
-90.0f * G_PI / 180.0f,
126
0.0f * G_PI / 180.0f); // Point 4
128
(gdouble) width - padding + ZEROPOINT5,
129
(gdouble) height - radius - padding + ZEROPOINT5); // Point 5
131
(gdouble) width - padding - radius + ZEROPOINT5,
132
(gdouble) height - padding - radius + ZEROPOINT5,
134
0.0f * G_PI / 180.0f,
135
90.0f * G_PI / 180.0f); // Point 7
137
anchor_width + padding + radius + ZEROPOINT5,
138
(gdouble) height - padding + ZEROPOINT5); // Point 8
141
anchor_width + padding + radius + ZEROPOINT5,
142
(gdouble) height - padding - radius,
144
90.0f * G_PI / 180.0f,
145
180.0f * G_PI / 180.0f); // Point 10
148
padding + anchor_width + ZEROPOINT5,
149
(gdouble) height - padding - radius - HeightToAnchor + ZEROPOINT5 ); // Point 11
151
padding + ZEROPOINT5,
152
(gdouble) height - padding - radius - HeightToAnchor - anchor_height / 2.0f + ZEROPOINT5); // Point 12
154
padding + anchor_width + ZEROPOINT5,
155
(gdouble) height - padding - radius - HeightToAnchor - anchor_height + ZEROPOINT5); // Point 13
157
cairo_line_to (cr, padding + anchor_width + ZEROPOINT5,
158
padding + radius + ZEROPOINT5); // Point 14
160
padding + anchor_width + radius + ZEROPOINT5,
161
padding + radius + ZEROPOINT5,
163
180.0f * G_PI / 180.0f,
164
270.0f * G_PI / 180.0f);
166
cairo_close_path (cr);
170
ComputeMask (cairo_t* cr)
172
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
173
cairo_fill_preserve (cr);
177
nux::Tooltip::ComputeOutline (cairo_t* cr,
182
gfloat corner_radius,
185
cairo_pattern_t* pattern = NULL;
190
g_warning ("%s(): passed in width is 0!", G_STRFUNC);
194
offset = ((double) padding_size + anchor_width) / (double) width;
196
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
197
cairo_set_line_width (cr, line_width);
199
pattern = cairo_pattern_create_linear (0.0, 0.0, (double) width, 0.0);
200
cairo_pattern_add_color_stop_rgba (pattern,
206
cairo_pattern_add_color_stop_rgba (pattern,
212
cairo_pattern_add_color_stop_rgba (pattern,
218
cairo_pattern_add_color_stop_rgba (pattern,
225
cairo_set_source (cr, pattern);
227
cairo_pattern_destroy (pattern);
231
Tooltip::DrawTintDotHighlight (cairo_t* cr,
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;
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);
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);
255
// prepare drawing for normal context
256
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
258
// create path in normal context
259
ComputeFullMaskPath (cr,
267
//cairo_rectangle (cr, 0.0f, 0.0f, (gdouble) width, (gdouble) height);
269
// fill path of normal context with tint
270
cairo_set_source_rgba (cr,
275
cairo_fill_preserve (cr);
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,
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);
292
dots_pattern = cairo_pattern_create_for_surface (dots_surf);
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);
308
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
309
hl_pattern = cairo_pattern_create_radial (hl_x,
315
cairo_pattern_add_color_stop_rgba (hl_pattern,
321
cairo_pattern_add_color_stop_rgba (hl_pattern,
327
cairo_set_source (cr, hl_pattern);
329
cairo_pattern_destroy (hl_pattern);
333
Tooltip::DrawMask (cairo_t* cr,
339
gfloat anchor_height,
347
ComputeFullMaskPath (cr,
360
#if defined(NUX_OS_LINUX)
361
Display* display = NULL;
363
double dpyWidth = 0.0;
364
double dpyHeight = 0.0;
365
double dpyWidthMM = 0.0;
366
double dpyHeightMM = 0.0;
370
display = XOpenDisplay (NULL);
371
screen = DefaultScreen (display);
373
dpyWidth = (double) DisplayWidth (display, screen);
374
dpyHeight = (double) DisplayHeight (display, screen);
375
dpyWidthMM = (double) DisplayWidthMM (display, screen);
376
dpyHeightMM = (double) DisplayHeightMM (display, screen);
378
dpiX = dpyWidth * 25.4 / dpyWidthMM;
379
dpiY = dpyHeight * 25.4 / dpyHeightMM;
381
_dpiX = (int) (dpiX + 0.5);
382
_dpiY = (int) (dpiY + 0.5);
384
XCloseDisplay (display);
385
#elif defined(NUX_OS_WINDOWS)
392
Tooltip::GetTextExtents (char* font,
396
cairo_surface_t* surface = NULL;
398
PangoLayout* layout = NULL;
399
PangoFontDescription* desc = NULL;
400
PangoContext* pangoCtx = NULL;
401
PangoRectangle logRect = {0, 0, 0, 0};
404
if (!font || !width || !height)
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);
422
*width = logRect.width / PANGO_SCALE;
423
*height = logRect.height / PANGO_SCALE;
426
pango_font_description_free (desc);
427
g_object_unref (layout);
429
cairo_surface_destroy (surface);
433
Tooltip::DrawLabel (cairo_t* cr,
440
PangoLayout* layout = NULL;
441
PangoFontDescription* desc = NULL;
442
PangoContext* pangoCtx = NULL;
444
GetTextExtents ((char*) FONT_FACE,
448
cairo_set_source_rgba (cr, rgba[0], rgba[1], rgba[2], rgba[3]);
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);
464
ANCHOR_WIDTH + (float) ((width - ANCHOR_WIDTH) - textWidth) / 2.0f,
465
(float) (height - textHeight) / 2.0f);
466
pango_cairo_show_layout (cr, layout);
470
pango_font_description_free (desc);
471
g_object_unref (layout);
475
Tooltip::DrawOutlineShadow (cairo_t* cr,
479
gfloat anchor_height,
481
gfloat corner_radius,
488
ComputeFullMaskPath (cr,
496
//DrawCairo (cr, TRUE, line_width, rgba_shadow, FALSE, FALSE);
497
//ctk_surface_blur (surf, blur_coeff);
512
_labelText = TEXT ("unset");
513
_fontOpts = cairo_font_options_create ();
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);
522
// make sure _dpiX and _dpiY are initialized correctly
528
cairo_font_options_destroy (_fontOpts);
529
delete(_cairo_graphics);
534
Tooltip::ProcessEvent (IEvent& ievent,
536
long ProcessEventInfo)
542
Tooltip::Draw (GraphicsContext& gfxContext,
545
Geometry base = GetGeometry();
547
// the elements position inside the window are referenced to top-left window
548
// corner. So bring base to (0, 0).
551
gfxContext.PushClippingRectangle (base);
553
gPainter.PushDrawShapeLayer (gfxContext,
555
eSHAPE_CORNER_ROUND10,
556
m_background_color, eAllCorners, true);
558
TexCoordXForm texxform;
559
texxform.SetWrap(TEXWRAP_REPEAT, TEXWRAP_REPEAT);
560
texxform.SetTexCoordType (TexCoordXForm::OFFSET_COORD);
562
gfxContext.QRP_GLSL_1Tex (base.x,
566
_texture2D->GetDeviceTexture(),
568
Color(1.0f, 1.0f, 1.0f, 1.0f));
570
gPainter.PopBackground ();
571
gfxContext.PopClippingRectangle ();
575
Tooltip::DrawContent (GraphicsContext& GfxContext,
578
/*Geometry base = GetGeometry();
581
// The elements position inside the window are referenced to top-left window corner. So bring base to (0, 0).
585
if (UseBlurredBackground() )
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);
592
gPainter.PushTextureLayer (GfxContext, base, GetThreadWindowCompositor().GetScreenBlurTexture(), texxform, Color::White, true);
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));
604
GfxContext.PushClippingRectangle (base);
605
m_layout->ProcessDraw (GfxContext, force_draw);
606
GfxContext.PopClippingRectangle();
609
gPainter.PopBackground();*/
612
void Tooltip::PreLayoutManagement ()
619
GetTextExtents ((char*) FONT_FACE,
623
newWidth = textWidth + 2 * H_MARGIN + ANCHOR_WIDTH + 2 * PADDING_SIZE;
624
newHeight = textHeight + 2 * V_MARGIN + 2 * PADDING_SIZE;
625
SetBaseSize (newWidth, newHeight);
629
BaseWindow::PreLayoutManagement ();
633
Tooltip::UpdateTexture ()
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;
643
_cairo_graphics = new CairoGraphics (CAIRO_FORMAT_ARGB32,
646
cairo_t *cr = _cairo_graphics->GetContext ();
648
highLightY = HIGH_LIGHT_Y;
649
if (GetBaseWidth () / 1.5f < HIGH_LIGHT_MIN_WIDTH)
650
highLightW = HIGH_LIGHT_MIN_WIDTH;
652
highLightW = GetBaseWidth () / 1.5f;
654
DrawTintDotHighlight (cr,
657
GetBaseWidth () / 2.0f,
663
DrawOutlineShadow (cr,
681
NBitmapData* bitmap = _cairo_graphics->GetBitmap();
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);
688
delete _cairo_graphics;
692
Tooltip::PostLayoutManagement (long LayoutResult)
694
long result = BaseWindow::PostLayoutManagement (LayoutResult);
700
Tooltip::PositionChildLayout (float offsetX,
706
Tooltip::LayoutWindowElements ()
711
Tooltip::NotifyConfigurationChange (int width,
717
Tooltip::SetText (NString text)
719
if (_labelText == text)