40
NUX_IMPLEMENT_OBJECT_TYPE (Tooltip);
44
_name = g_strdup ("Tooltip");
48
_cairo_text_has_changed = true;
52
_labelText = TEXT ("Unity");
60
_hlayout = new nux::HLayout (TEXT(""), NUX_TRACKER_LOCATION);
61
_vlayout = new nux::VLayout (TEXT(""), NUX_TRACKER_LOCATION);
63
_left_space = new nux::SpaceLayout (_padding + _anchor_width + _corner_radius, _padding + _anchor_width + _corner_radius, 1, 1000);
64
_right_space = new nux::SpaceLayout (_padding + _corner_radius, _padding + _corner_radius, 1, 1000);
66
_top_space = new nux::SpaceLayout (1, 1000, _padding + _corner_radius, _padding + _corner_radius);
67
_bottom_space = new nux::SpaceLayout (1, 1000, _padding + _corner_radius, _padding + _corner_radius);
69
_vlayout->AddLayout(_top_space, 0);
71
_tooltip_text = new nux::StaticCairoText (_labelText.GetTCharPtr (), NUX_TRACKER_LOCATION);
72
_on_text_changed_connection = (sigc::connection) _tooltip_text->sigTextChanged.connect (sigc::mem_fun (this, &Tooltip::RecvCairoTextChanged));
73
_on_font_changed_connection = (sigc::connection) _tooltip_text->sigFontChanged.connect (sigc::mem_fun (this, &Tooltip::RecvCairoTextChanged));
74
_tooltip_text->Reference();
76
_vlayout->AddView(_tooltip_text, 1, eCenter, eFull);
78
_vlayout->AddLayout(_bottom_space, 0);
80
_hlayout->AddLayout(_left_space, 0);
81
_hlayout->AddLayout(_vlayout, 1, eCenter, eFull);
82
_hlayout->AddLayout(_right_space, 0);
84
SetWindowSizeMatchLayout (true);
95
_texture_bg->UnReference ();
97
if (_on_text_changed_connection.connected ())
98
_on_text_changed_connection.disconnect ();
100
if (_on_font_changed_connection.connected ())
101
_on_font_changed_connection.disconnect ();
103
_tooltip_text->UnReference();
106
long Tooltip::ProcessEvent (IEvent& ievent, long TraverseInfo, long ProcessEventInfo)
108
long ret = TraverseInfo;
110
_tooltip_text->ProcessEvent(ievent, ret, ProcessEventInfo);
115
void Tooltip::ShowTooltipWithTipAt (int anchor_tip_x, int anchor_tip_y)
117
_anchorX = anchor_tip_x;
118
_anchorY = anchor_tip_y;
120
int x = _anchorX - _padding;
121
int y = anchor_tip_y - _anchor_height/2 - _top_size - _corner_radius - _padding;
129
UBusServer *ubus = ubus_server_get_default ();
130
ubus_server_send_message (ubus, UBUS_TOOLTIP_SHOWN, NULL);
133
void Tooltip::Draw (GraphicsEngine& gfxContext, bool forceDraw)
135
Geometry base = GetGeometry();
137
// the elements position inside the window are referenced to top-left window
138
// corner. So bring base to (0, 0).
141
gfxContext.PushClippingRectangle (base);
143
GetGraphicsEngine().GetRenderStates().SetBlend (false);
145
TexCoordXForm texxform_bg;
146
texxform_bg.SetWrap(TEXWRAP_CLAMP, TEXWRAP_CLAMP);
147
texxform_bg.SetTexCoordType (TexCoordXForm::OFFSET_COORD);
149
TexCoordXForm texxform_mask;
150
texxform_mask.SetWrap(TEXWRAP_CLAMP, TEXWRAP_CLAMP);
151
texxform_mask.SetTexCoordType (TexCoordXForm::OFFSET_COORD);
154
gfxContext.QRP_2TexMod (base.x,
158
_texture_bg->GetDeviceTexture(),
160
Color(1.0f, 1.0f, 1.0f, 1.0f),
161
_texture_mask->GetDeviceTexture(),
163
Color(1.0f, 1.0f, 1.0f, 1.0f));
166
TexCoordXForm texxform;
167
texxform.SetWrap(TEXWRAP_CLAMP, TEXWRAP_CLAMP);
168
texxform.SetTexCoordType (TexCoordXForm::OFFSET_COORD);
170
GetGraphicsEngine ().GetRenderStates ().SetBlend (true);
171
GetGraphicsEngine ().GetRenderStates ().SetPremultipliedBlend (nux::SRC_OVER);
172
gfxContext.QRP_1Tex (base.x,
176
_texture_outline->GetDeviceTexture(),
178
Color(1.0f, 1.0f, 1.0f, 1.0f));
180
GetGraphicsEngine().GetRenderStates().SetBlend (false);
182
_tooltip_text->ProcessDraw(gfxContext, forceDraw);
184
gfxContext.PopClippingRectangle ();
187
void Tooltip::DrawContent (GraphicsEngine& GfxContext, bool force_draw)
192
void Tooltip::PreLayoutManagement ()
194
int MaxItemWidth = 0;
195
int TotalItemHeight = 0;
199
_tooltip_text->GetTextExtents(textWidth, textHeight);
201
if (textWidth > MaxItemWidth)
202
MaxItemWidth = textWidth;
203
TotalItemHeight += textHeight;
206
if(TotalItemHeight < _anchor_height)
208
_top_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight)/2 + _padding + _corner_radius);
209
_bottom_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight)/2 +1 + _padding + _corner_radius);
212
BaseWindow::PreLayoutManagement ();
215
long Tooltip::PostLayoutManagement (long LayoutResult)
217
long result = BaseWindow::PostLayoutManagement (LayoutResult);
223
void Tooltip::RecvCairoTextChanged (StaticCairoText* cairo_text)
225
_cairo_text_has_changed = true;
228
/////////////////////////////////////////////////////////////////////////////////////////////////
229
/////////////////////////////////////////////////////////////////////////////////////////////////
230
/////////////////////////////////////////////////////////////////////////////////////////////////
232
void tint_dot_hl (cairo_t* cr,
242
// clear normal context
243
cairo_scale (cr, 1.0f, 1.0f);
244
cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
245
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
248
// prepare drawing for normal context
249
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
251
// create path in normal context
252
cairo_rectangle (cr, 0.0f, 0.0f, (gdouble) width, (gdouble) height);
254
// fill path of normal context with tint
255
cairo_set_source_rgba (cr,
263
void _setup (cairo_surface_t** surf,
271
cairo_scale (*cr, 1.0f, 1.0f);
274
cairo_set_source_rgba (*cr, 0.0f, 0.0f, 0.0f, 0.0f);
275
cairo_set_operator (*cr, CAIRO_OPERATOR_CLEAR);
279
cairo_set_operator (*cr, CAIRO_OPERATOR_OVER);
281
cairo_set_source_rgba (*cr, 0.0f, 0.0f, 0.0f, 0.0f);
283
cairo_set_source_rgba (*cr, 1.0f, 1.0f, 1.0f, 1.0f);
288
void _compute_full_mask_path (cairo_t* cr,
290
gfloat anchor_height,
316
// +--+--------+--+ 6
320
gfloat padding = pad;
321
int ZEROPOINT5 = 0.0f;
323
gfloat HeightToAnchor = 0.0f;
324
HeightToAnchor = ((gfloat) height - 2.0f * radius - anchor_height -2*padding) / 2.0f;
325
if (HeightToAnchor < 0.0f)
327
g_warning ("Anchor-height and corner-radius a higher than whole texture!");
333
if(upper_size > height - 2.0f * radius - anchor_height -2 * padding)
335
//g_warning ("[_compute_full_mask_path] incorrect upper_size value");
340
HeightToAnchor = height - 2.0f * radius - anchor_height -2 * padding - upper_size;
345
HeightToAnchor = (height - 2.0f * radius - anchor_height -2*padding) / 2.0f;
348
cairo_translate (cr, -0.5f, -0.5f);
351
cairo_move_to (cr, padding + anchor_width + radius + ZEROPOINT5, padding + ZEROPOINT5); // Point 1
352
cairo_line_to (cr, width - padding - radius, padding + ZEROPOINT5); // Point 2
354
width - padding - radius + ZEROPOINT5,
355
padding + radius + ZEROPOINT5,
357
-90.0f * G_PI / 180.0f,
358
0.0f * G_PI / 180.0f); // Point 4
360
(gdouble) width - padding + ZEROPOINT5,
361
(gdouble) height - radius - padding + ZEROPOINT5); // Point 5
363
(gdouble) width - padding - radius + ZEROPOINT5,
364
(gdouble) height - padding - radius + ZEROPOINT5,
366
0.0f * G_PI / 180.0f,
367
90.0f * G_PI / 180.0f); // Point 7
369
anchor_width + padding + radius + ZEROPOINT5,
370
(gdouble) height - padding + ZEROPOINT5); // Point 8
373
anchor_width + padding + radius + ZEROPOINT5,
374
(gdouble) height - padding - radius,
376
90.0f * G_PI / 180.0f,
377
180.0f * G_PI / 180.0f); // Point 10
380
padding + anchor_width + ZEROPOINT5,
381
(gdouble) height - padding - radius - HeightToAnchor + ZEROPOINT5 ); // Point 11
383
padding + ZEROPOINT5,
384
(gdouble) height - padding - radius - HeightToAnchor - anchor_height / 2.0f + ZEROPOINT5); // Point 12
386
padding + anchor_width + ZEROPOINT5,
387
(gdouble) height - padding - radius - HeightToAnchor - anchor_height + ZEROPOINT5); // Point 13
389
cairo_line_to (cr, padding + anchor_width + ZEROPOINT5, padding + radius + ZEROPOINT5); // Point 14
391
padding + anchor_width + radius + ZEROPOINT5,
392
padding + radius + ZEROPOINT5,
394
180.0f * G_PI / 180.0f,
395
270.0f * G_PI / 180.0f);
397
cairo_close_path (cr);
400
void compute_mask (cairo_t* cr)
402
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
403
cairo_fill_preserve (cr);
406
void compute_outline (cairo_t* cr,
410
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
411
cairo_set_source_rgba (cr,
416
cairo_set_line_width (cr, line_width);
420
void _draw (cairo_t* cr,
428
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
430
// actually draw the mask
433
cairo_set_line_width (cr, line_width);
434
cairo_set_source_rgba (cr, rgba[0], rgba[1], rgba[2], rgba[3]);
439
cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f);
441
cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.0f);
446
cairo_stroke_preserve (cr);
448
cairo_fill_preserve (cr);
451
void _finalize (cairo_t** cr,
459
cairo_set_operator (*cr, CAIRO_OPERATOR_SOURCE);
461
// actually draw the mask
464
cairo_set_line_width (*cr, line_width);
465
cairo_set_source_rgba (*cr, rgba[0], rgba[1], rgba[2], rgba[3]);
470
cairo_set_source_rgba (*cr, 1.0f, 1.0f, 1.0f, 1.0f);
472
cairo_set_source_rgba (*cr, 0.0f, 0.0f, 0.0f, 0.0f);
483
compute_full_outline_shadow (
485
cairo_surface_t* surf,
489
gfloat anchor_height,
491
gfloat corner_radius,
498
_setup (&surf, &cr, TRUE, width, height, FALSE);
499
_compute_full_mask_path (cr,
508
_draw (cr, TRUE, line_width, rgba_shadow, FALSE, FALSE);
509
CairoGraphics* dummy = new CairoGraphics (CAIRO_FORMAT_A1, 1, 1);
510
dummy->BlurSurface (blur_coeff, surf);
515
void compute_full_mask (
517
cairo_surface_t* surf,
523
gfloat anchor_height,
531
_setup (&surf, &cr, outline, width, height, negative);
532
_compute_full_mask_path (cr,
540
_finalize (&cr, outline, line_width, rgba, negative, outline);
543
void Tooltip::UpdateTexture ()
545
if (_cairo_text_has_changed == false)
548
int height = GetBaseHeight ();
551
int x = _anchorX - _padding;
552
int y = _anchorY - height/2;
557
float blur_coef = 6.0f;
559
CairoGraphics* cairo_bg = new CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());
560
CairoGraphics* cairo_mask = new CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());
561
CairoGraphics* cairo_outline = new CairoGraphics (CAIRO_FORMAT_ARGB32, GetBaseWidth (), GetBaseHeight ());
563
cairo_t *cr_bg = cairo_bg->GetContext ();
564
cairo_t *cr_mask = cairo_mask->GetContext ();
565
cairo_t *cr_outline = cairo_outline->GetContext ();
567
float tint_color[4] = {0.074f, 0.074f, 0.074f, 0.80f};
568
float hl_color[4] = {1.0f, 1.0f, 1.0f, 0.15f};
569
float dot_color[4] = {1.0f, 1.0f, 1.0f, 0.20f};
570
float shadow_color[4] = {0.0f, 0.0f, 0.0f, 1.00f};
571
float outline_color[4] = {1.0f, 1.0f, 1.0f, 0.75f};
572
float mask_color[4] = {1.0f, 1.0f, 1.0f, 1.00f};
577
GetBaseWidth () / 2.0f,
579
Max<float>(GetBaseWidth () / 1.3f, GetBaseHeight () / 1.3f),
584
compute_full_outline_shadow
587
cairo_outline->GetSurface(),
602
cairo_mask->GetSurface(),
605
_corner_radius, // radius,
606
16, // shadow_radius,
607
_anchor_width, // anchor_width,
608
_anchor_height, // anchor_height,
613
_padding, // padding_size,
616
cairo_destroy (cr_bg);
617
cairo_destroy (cr_outline);
618
cairo_destroy (cr_mask);
620
NBitmapData* bitmap = cairo_bg->GetBitmap();
623
_texture_bg->UnReference ();
624
_texture_bg = GetGraphicsDisplay ()->GetGpuDevice ()->CreateSystemCapableTexture ();
625
_texture_bg->Update(bitmap);
628
bitmap = cairo_mask->GetBitmap();
630
_texture_mask->UnReference ();
631
_texture_mask = GetGraphicsDisplay ()->GetGpuDevice ()->CreateSystemCapableTexture ();
632
_texture_mask->Update(bitmap);
635
bitmap = cairo_outline->GetBitmap();
636
if (_texture_outline)
637
_texture_outline->UnReference ();
638
_texture_outline = GetGraphicsDisplay ()->GetGpuDevice ()->CreateSystemCapableTexture ();
639
_texture_outline->Update(bitmap);
644
delete cairo_outline;
645
_cairo_text_has_changed = false;
648
void Tooltip::PositionChildLayout (float offsetX,
653
void Tooltip::LayoutWindowElements ()
657
void Tooltip::NotifyConfigurationChange (int width,
662
void Tooltip::SetText (NString text)
664
if (_labelText == text)
668
_tooltip_text->SetText (_labelText);
674
const gchar* Tooltip::GetName ()
676
return g_strdup (_name);
679
void Tooltip::AddProperties (GVariantBuilder *builder)
681
g_variant_builder_add (builder, "{sv}", "text", g_variant_new_string (_labelText.GetTCharPtr ()));
682
g_variant_builder_add (builder, "{sv}", "x", g_variant_new_int32 (GetBaseX ()));
683
g_variant_builder_add (builder, "{sv}", "y", g_variant_new_int32 (GetBaseY ()));
684
g_variant_builder_add (builder, "{sv}", "width", g_variant_new_int32 (GetBaseWidth ()));
685
g_variant_builder_add (builder, "{sv}", "height", g_variant_new_int32 (GetBaseHeight ()));
686
g_variant_builder_add (builder, "{sv}", "active", g_variant_new_boolean (IsVisible ()));
40
NUX_IMPLEMENT_OBJECT_TYPE(Tooltip);
44
_name = g_strdup("Tooltip");
48
_cairo_text_has_changed = true;
52
_labelText = TEXT("Unity");
60
_hlayout = new nux::HLayout(TEXT(""), NUX_TRACKER_LOCATION);
61
_vlayout = new nux::VLayout(TEXT(""), NUX_TRACKER_LOCATION);
63
_left_space = new nux::SpaceLayout(_padding + _anchor_width + _corner_radius, _padding + _anchor_width + _corner_radius, 1, 1000);
64
_right_space = new nux::SpaceLayout(_padding + _corner_radius, _padding + _corner_radius, 1, 1000);
66
_top_space = new nux::SpaceLayout(1, 1000, _padding + _corner_radius, _padding + _corner_radius);
67
_bottom_space = new nux::SpaceLayout(1, 1000, _padding + _corner_radius, _padding + _corner_radius);
69
_vlayout->AddLayout(_top_space, 0);
71
_tooltip_text = new nux::StaticCairoText(_labelText.GetTCharPtr(), NUX_TRACKER_LOCATION);
72
_tooltip_text->sigTextChanged.connect(sigc::mem_fun(this, &Tooltip::RecvCairoTextChanged));
73
_tooltip_text->sigFontChanged.connect(sigc::mem_fun(this, &Tooltip::RecvCairoTextChanged));
74
_tooltip_text->Reference();
76
_vlayout->AddView(_tooltip_text, 1, eCenter, eFull);
78
_vlayout->AddLayout(_bottom_space, 0);
80
_hlayout->AddLayout(_left_space, 0);
81
_hlayout->AddLayout(_vlayout, 1, eCenter, eFull);
82
_hlayout->AddLayout(_right_space, 0);
84
SetWindowSizeMatchLayout(true);
95
_texture_bg->UnReference();
97
_tooltip_text->UnReference();
100
long Tooltip::ProcessEvent(IEvent& ievent, long TraverseInfo, long ProcessEventInfo)
102
long ret = TraverseInfo;
104
_tooltip_text->ProcessEvent(ievent, ret, ProcessEventInfo);
109
void Tooltip::ShowTooltipWithTipAt(int anchor_tip_x, int anchor_tip_y)
111
_anchorX = anchor_tip_x;
112
_anchorY = anchor_tip_y;
114
int x = _anchorX - _padding;
115
int y = anchor_tip_y - _anchor_height / 2 - _top_size - _corner_radius - _padding;
123
UBusServer* ubus = ubus_server_get_default();
124
ubus_server_send_message(ubus, UBUS_TOOLTIP_SHOWN, NULL);
127
void Tooltip::Draw(GraphicsEngine& gfxContext, bool forceDraw)
129
Geometry base = GetGeometry();
131
// the elements position inside the window are referenced to top-left window
132
// corner. So bring base to (0, 0).
135
gfxContext.PushClippingRectangle(base);
137
GetGraphicsEngine().GetRenderStates().SetBlend(false);
139
TexCoordXForm texxform_bg;
140
texxform_bg.SetWrap(TEXWRAP_CLAMP, TEXWRAP_CLAMP);
141
texxform_bg.SetTexCoordType(TexCoordXForm::OFFSET_COORD);
143
TexCoordXForm texxform_mask;
144
texxform_mask.SetWrap(TEXWRAP_CLAMP, TEXWRAP_CLAMP);
145
texxform_mask.SetTexCoordType(TexCoordXForm::OFFSET_COORD);
148
gfxContext.QRP_2TexMod(base.x,
152
_texture_bg->GetDeviceTexture(),
154
Color(1.0f, 1.0f, 1.0f, 1.0f),
155
_texture_mask->GetDeviceTexture(),
157
Color(1.0f, 1.0f, 1.0f, 1.0f));
160
TexCoordXForm texxform;
161
texxform.SetWrap(TEXWRAP_CLAMP, TEXWRAP_CLAMP);
162
texxform.SetTexCoordType(TexCoordXForm::OFFSET_COORD);
164
GetGraphicsEngine().GetRenderStates().SetBlend(true);
165
GetGraphicsEngine().GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
166
gfxContext.QRP_1Tex(base.x,
170
_texture_outline->GetDeviceTexture(),
172
Color(1.0f, 1.0f, 1.0f, 1.0f));
174
GetGraphicsEngine().GetRenderStates().SetBlend(false);
176
_tooltip_text->ProcessDraw(gfxContext, forceDraw);
178
gfxContext.PopClippingRectangle();
181
void Tooltip::DrawContent(GraphicsEngine& GfxContext, bool force_draw)
186
void Tooltip::PreLayoutManagement()
188
int MaxItemWidth = 0;
189
int TotalItemHeight = 0;
193
_tooltip_text->GetTextExtents(textWidth, textHeight);
195
if (textWidth > MaxItemWidth)
196
MaxItemWidth = textWidth;
197
TotalItemHeight += textHeight;
200
if (TotalItemHeight < _anchor_height)
202
_top_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight) / 2 + _padding + _corner_radius);
203
_bottom_space->SetMinMaxSize(1, (_anchor_height - TotalItemHeight) / 2 + 1 + _padding + _corner_radius);
206
BaseWindow::PreLayoutManagement();
209
long Tooltip::PostLayoutManagement(long LayoutResult)
211
long result = BaseWindow::PostLayoutManagement(LayoutResult);
217
void Tooltip::RecvCairoTextChanged(StaticCairoText* cairo_text)
219
_cairo_text_has_changed = true;
222
/////////////////////////////////////////////////////////////////////////////////////////////////
223
/////////////////////////////////////////////////////////////////////////////////////////////////
224
/////////////////////////////////////////////////////////////////////////////////////////////////
226
void tint_dot_hl(cairo_t* cr,
236
// clear normal context
237
cairo_scale(cr, 1.0f, 1.0f);
238
cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
239
cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
242
// prepare drawing for normal context
243
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
245
// create path in normal context
246
cairo_rectangle(cr, 0.0f, 0.0f, (gdouble) width, (gdouble) height);
248
// fill path of normal context with tint
249
cairo_set_source_rgba(cr,
257
void _setup(cairo_surface_t** surf,
265
cairo_scale(*cr, 1.0f, 1.0f);
268
cairo_set_source_rgba(*cr, 0.0f, 0.0f, 0.0f, 0.0f);
269
cairo_set_operator(*cr, CAIRO_OPERATOR_CLEAR);
273
cairo_set_operator(*cr, CAIRO_OPERATOR_OVER);
275
cairo_set_source_rgba(*cr, 0.0f, 0.0f, 0.0f, 0.0f);
277
cairo_set_source_rgba(*cr, 1.0f, 1.0f, 1.0f, 1.0f);
282
void _compute_full_mask_path(cairo_t* cr,
284
gfloat anchor_height,
310
// +--+--------+--+ 6
314
gfloat padding = pad;
315
int ZEROPOINT5 = 0.0f;
317
gfloat HeightToAnchor = 0.0f;
318
HeightToAnchor = ((gfloat) height - 2.0f * radius - anchor_height - 2 * padding) / 2.0f;
319
if (HeightToAnchor < 0.0f)
321
g_warning("Anchor-height and corner-radius a higher than whole texture!");
327
if (upper_size > height - 2.0f * radius - anchor_height - 2 * padding)
329
//g_warning ("[_compute_full_mask_path] incorrect upper_size value");
334
HeightToAnchor = height - 2.0f * radius - anchor_height - 2 * padding - upper_size;
339
HeightToAnchor = (height - 2.0f * radius - anchor_height - 2 * padding) / 2.0f;
342
cairo_translate(cr, -0.5f, -0.5f);
345
cairo_move_to(cr, padding + anchor_width + radius + ZEROPOINT5, padding + ZEROPOINT5); // Point 1
346
cairo_line_to(cr, width - padding - radius, padding + ZEROPOINT5); // Point 2
348
width - padding - radius + ZEROPOINT5,
349
padding + radius + ZEROPOINT5,
351
-90.0f * G_PI / 180.0f,
352
0.0f * G_PI / 180.0f); // Point 4
354
(gdouble) width - padding + ZEROPOINT5,
355
(gdouble) height - radius - padding + ZEROPOINT5); // Point 5
357
(gdouble) width - padding - radius + ZEROPOINT5,
358
(gdouble) height - padding - radius + ZEROPOINT5,
360
0.0f * G_PI / 180.0f,
361
90.0f * G_PI / 180.0f); // Point 7
363
anchor_width + padding + radius + ZEROPOINT5,
364
(gdouble) height - padding + ZEROPOINT5); // Point 8
367
anchor_width + padding + radius + ZEROPOINT5,
368
(gdouble) height - padding - radius,
370
90.0f * G_PI / 180.0f,
371
180.0f * G_PI / 180.0f); // Point 10
374
padding + anchor_width + ZEROPOINT5,
375
(gdouble) height - padding - radius - HeightToAnchor + ZEROPOINT5); // Point 11
377
padding + ZEROPOINT5,
378
(gdouble) height - padding - radius - HeightToAnchor - anchor_height / 2.0f + ZEROPOINT5); // Point 12
380
padding + anchor_width + ZEROPOINT5,
381
(gdouble) height - padding - radius - HeightToAnchor - anchor_height + ZEROPOINT5); // Point 13
383
cairo_line_to(cr, padding + anchor_width + ZEROPOINT5, padding + radius + ZEROPOINT5); // Point 14
385
padding + anchor_width + radius + ZEROPOINT5,
386
padding + radius + ZEROPOINT5,
388
180.0f * G_PI / 180.0f,
389
270.0f * G_PI / 180.0f);
391
cairo_close_path(cr);
394
void compute_mask(cairo_t* cr)
396
cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
397
cairo_fill_preserve(cr);
400
void compute_outline(cairo_t* cr,
404
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
405
cairo_set_source_rgba(cr,
410
cairo_set_line_width(cr, line_width);
414
void _draw(cairo_t* cr,
422
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
424
// actually draw the mask
427
cairo_set_line_width(cr, line_width);
428
cairo_set_source_rgba(cr, rgba[0], rgba[1], rgba[2], rgba[3]);
433
cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f);
435
cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.0f);
440
cairo_stroke_preserve(cr);
442
cairo_fill_preserve(cr);
445
void _finalize(cairo_t** cr,
453
cairo_set_operator(*cr, CAIRO_OPERATOR_SOURCE);
455
// actually draw the mask
458
cairo_set_line_width(*cr, line_width);
459
cairo_set_source_rgba(*cr, rgba[0], rgba[1], rgba[2], rgba[3]);
464
cairo_set_source_rgba(*cr, 1.0f, 1.0f, 1.0f, 1.0f);
466
cairo_set_source_rgba(*cr, 0.0f, 0.0f, 0.0f, 0.0f);
477
compute_full_outline_shadow(
479
cairo_surface_t* surf,
483
gfloat anchor_height,
485
gfloat corner_radius,
492
_setup(&surf, &cr, TRUE, width, height, FALSE);
493
_compute_full_mask_path(cr,
502
_draw(cr, TRUE, line_width, rgba_shadow, FALSE, FALSE);
503
CairoGraphics* dummy = new CairoGraphics(CAIRO_FORMAT_A1, 1, 1);
504
dummy->BlurSurface(blur_coeff, surf);
509
void compute_full_mask(
511
cairo_surface_t* surf,
517
gfloat anchor_height,
525
_setup(&surf, &cr, outline, width, height, negative);
526
_compute_full_mask_path(cr,
534
_finalize(&cr, outline, line_width, rgba, negative, outline);
537
void Tooltip::UpdateTexture()
539
if (_cairo_text_has_changed == false)
542
int height = GetBaseHeight();
545
int x = _anchorX - _padding;
546
int y = _anchorY - height / 2;
551
float blur_coef = 6.0f;
553
CairoGraphics* cairo_bg = new CairoGraphics(CAIRO_FORMAT_ARGB32, GetBaseWidth(), GetBaseHeight());
554
CairoGraphics* cairo_mask = new CairoGraphics(CAIRO_FORMAT_ARGB32, GetBaseWidth(), GetBaseHeight());
555
CairoGraphics* cairo_outline = new CairoGraphics(CAIRO_FORMAT_ARGB32, GetBaseWidth(), GetBaseHeight());
557
cairo_t* cr_bg = cairo_bg->GetContext();
558
cairo_t* cr_mask = cairo_mask->GetContext();
559
cairo_t* cr_outline = cairo_outline->GetContext();
561
float tint_color[4] = {0.074f, 0.074f, 0.074f, 0.80f};
562
float hl_color[4] = {1.0f, 1.0f, 1.0f, 0.15f};
563
float dot_color[4] = {1.0f, 1.0f, 1.0f, 0.20f};
564
float shadow_color[4] = {0.0f, 0.0f, 0.0f, 1.00f};
565
float outline_color[4] = {1.0f, 1.0f, 1.0f, 0.75f};
566
float mask_color[4] = {1.0f, 1.0f, 1.0f, 1.00f};
571
GetBaseWidth() / 2.0f,
573
Max<float>(GetBaseWidth() / 1.3f, GetBaseHeight() / 1.3f),
578
compute_full_outline_shadow
581
cairo_outline->GetSurface(),
596
cairo_mask->GetSurface(),
599
_corner_radius, // radius,
600
16, // shadow_radius,
601
_anchor_width, // anchor_width,
602
_anchor_height, // anchor_height,
607
_padding, // padding_size,
610
cairo_destroy(cr_bg);
611
cairo_destroy(cr_outline);
612
cairo_destroy(cr_mask);
614
NBitmapData* bitmap = cairo_bg->GetBitmap();
617
_texture_bg->UnReference();
618
_texture_bg = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
619
_texture_bg->Update(bitmap);
622
bitmap = cairo_mask->GetBitmap();
624
_texture_mask->UnReference();
625
_texture_mask = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
626
_texture_mask->Update(bitmap);
629
bitmap = cairo_outline->GetBitmap();
630
if (_texture_outline)
631
_texture_outline->UnReference();
632
_texture_outline = GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture();
633
_texture_outline->Update(bitmap);
638
delete cairo_outline;
639
_cairo_text_has_changed = false;
642
void Tooltip::PositionChildLayout(float offsetX,
647
void Tooltip::LayoutWindowElements()
651
void Tooltip::NotifyConfigurationChange(int width,
656
void Tooltip::SetText(NString text)
658
if (_labelText == text)
662
_tooltip_text->SetText(_labelText);
668
const gchar* Tooltip::GetName()
670
return g_strdup(_name);
673
void Tooltip::AddProperties(GVariantBuilder* builder)
675
g_variant_builder_add(builder, "{sv}", "text", g_variant_new_string(_labelText.GetTCharPtr()));
676
g_variant_builder_add(builder, "{sv}", "x", g_variant_new_int32(GetBaseX()));
677
g_variant_builder_add(builder, "{sv}", "y", g_variant_new_int32(GetBaseY()));
678
g_variant_builder_add(builder, "{sv}", "width", g_variant_new_int32(GetBaseWidth()));
679
g_variant_builder_add(builder, "{sv}", "height", g_variant_new_int32(GetBaseHeight()));
680
g_variant_builder_add(builder, "{sv}", "active", g_variant_new_boolean(IsVisible()));
689
683
} // namespace nux