2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 3
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
/*********************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by ChanGFu (for any bug report, please mail me to fabounet@users.berlios.de)
27
*********************************************************************************/
30
#include <cairo-dock.h>
32
#include "applet-struct.h"
33
#include "applet-decorator-tooltip.h"
36
#define _CAIRO_DIALOG_TOOLTIP_MIN_GAP 10
37
#define _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH 20
38
#define _CAIRO_DIALOG_TOOLTIP_ARROW_HEIGHT 5
41
void cd_decorator_set_frame_size_tooltip (CairoDialog *pDialog) {
42
int iMargin = .5 * myConfig.iTooltipLineWidth + (1. - sqrt (2) / 2) * myConfig.iTooltipRadius;
43
pDialog->iRightMargin = iMargin;
44
pDialog->iLeftMargin = iMargin;
45
pDialog->iTopMargin = 0;
46
pDialog->iBottomMargin = 0;
47
pDialog->iMinBottomGap = _CAIRO_DIALOG_TOOLTIP_MIN_GAP;
48
pDialog->iMinFrameWidth = _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH;
50
pDialog->fReflectAlpha = 0.;
54
void cd_decorator_draw_decorations_tooltip (cairo_t *pCairoContext, CairoDialog *pDialog) {
55
double fLineWidth = myConfig.iTooltipLineWidth;
56
double fRadius = myConfig.iTooltipRadius;
58
double fOffsetX = fRadius + fLineWidth / 2;
59
double fOffsetY = (pDialog->bDirectionUp ? fLineWidth / 2 : pDialog->iHeight - fLineWidth / 2);
60
int sens = (pDialog->bDirectionUp ? 1 : -1);
61
int iWidth = pDialog->iWidth;
63
//On se déplace la ou il le faut
64
cairo_move_to (pCairoContext, fOffsetX, fOffsetY);
66
// Ligne du haut (Haut gauche -> Haut Droite)
67
cairo_rel_line_to (pCairoContext, iWidth - (2 * fRadius + fLineWidth), 0);
70
cairo_rel_curve_to (pCairoContext,
73
fRadius, sens * fRadius);
75
// Ligne droite. (Haut droit -> Bas droit)
76
cairo_rel_line_to (pCairoContext, 0, sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
79
cairo_rel_curve_to (pCairoContext,
82
-fRadius, sens * fRadius);
85
double fDemiWidth = (iWidth - fLineWidth - 2 * fRadius - _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH)/2;
86
cairo_rel_line_to (pCairoContext, -fDemiWidth, 0);
87
cairo_rel_line_to (pCairoContext, - _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH/2, sens * _CAIRO_DIALOG_TOOLTIP_ARROW_HEIGHT);
88
cairo_rel_line_to (pCairoContext, - _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH/2, -sens * _CAIRO_DIALOG_TOOLTIP_ARROW_HEIGHT);
89
cairo_rel_line_to (pCairoContext, - fDemiWidth, 0);
92
cairo_rel_curve_to (pCairoContext,
95
-fRadius, -sens * fRadius);
98
cairo_rel_line_to (pCairoContext, 0, - sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
101
cairo_rel_curve_to (pCairoContext,
104
fRadius, -sens * fRadius);
106
cairo_close_path (pCairoContext);
108
cairo_set_source_rgba (pCairoContext, myDialogs.fDialogColor[0], myDialogs.fDialogColor[1], myDialogs.fDialogColor[2], myDialogs.fDialogColor[3]);
109
cairo_fill_preserve (pCairoContext); //Notre fond
110
cairo_set_source_rgba (pCairoContext, myConfig.fTooltipLineColor[0], myConfig.fTooltipLineColor[1], myConfig.fTooltipLineColor[2], myConfig.fTooltipLineColor[3]);
111
cairo_set_line_width (pCairoContext, fLineWidth); //La ligne externe
113
cairo_stroke (pCairoContext); //On ferme notre chemin
115
if (pDialog->iIconSize != 0) {
116
//Ajout d'un cadre pour l'icône (Pas d'alpha)
117
int iIconFrameWidth = (pDialog->iIconSize / 2) - (2 * fRadius + fLineWidth);
118
//cd_debug ("Tooltip: %d", iIconFrameWidth);
119
//cairo_move_to (pCairoContext, 0, 0); //On revient a l'origine
120
cairo_move_to (pCairoContext, fOffsetX + 2 * (fLineWidth + 1), fOffsetY + 2 * (fLineWidth + 1)); //Pour créer l'effet d'inclusion
121
//On trace une ligne HautGauche -> HautDroit
122
cairo_rel_line_to (pCairoContext, iIconFrameWidth, 0);
123
//On trace une ligne HautDroit -> BasDroit
124
cairo_rel_line_to (pCairoContext, 0, sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (fRadius + fLineWidth)));
125
//On trace une ligne BasDroit -> BasGauche
126
cairo_rel_line_to (pCairoContext, - iIconFrameWidth, 0);
128
cairo_rel_curve_to (pCairoContext,
131
-fRadius, -sens * fRadius);
132
//On trace une ligne BasGauche -> HautGauche
133
cairo_rel_line_to (pCairoContext, 0, - sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + 2 * (fLineWidth + 3.5))));
136
cairo_rel_curve_to (pCairoContext,
139
fRadius, -sens * fRadius);
142
cairo_close_path (pCairoContext);
144
cairo_set_source_rgba (pCairoContext, myConfig.fTooltipMarginColor[0], myConfig.fTooltipMarginColor[1], myConfig.fTooltipMarginColor[2], myConfig.fTooltipMarginColor[3]);
145
cairo_fill_preserve (pCairoContext);
146
cairo_set_source_rgba (pCairoContext, myConfig.fTooltipLineColor[0], myConfig.fTooltipLineColor[1], myConfig.fTooltipLineColor[2], myConfig.fTooltipLineColor[3]);
147
cairo_set_line_width (pCairoContext, fLineWidth);
149
cairo_stroke (pCairoContext);
154
void cd_decorator_register_tooltip (void)
156
CairoDialogDecorator *pDecorator = g_new (CairoDialogDecorator, 1);
157
pDecorator->set_size = cd_decorator_set_frame_size_tooltip;
158
pDecorator->render = cd_decorator_draw_decorations_tooltip;
159
pDecorator->render_opengl = NULL;
160
pDecorator->cDisplayedName = D_ (MY_APPLET_DECORATOR_TOOLTIP_NAME);
161
cairo_dock_register_dialog_decorator (MY_APPLET_DECORATOR_TOOLTIP_NAME, pDecorator);