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 Fabrice Rey (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-curly.h"
36
void cd_decorator_set_frame_size_curly (CairoDialog *pDialog) {
37
int iMargin = .5 * myConfig.iCurlyLineWidth + (1. - sqrt (2) / 2) * myConfig.iCurlyRadius;
38
pDialog->iRightMargin = iMargin;
39
pDialog->iLeftMargin = iMargin;
40
pDialog->iTopMargin = iMargin;
41
pDialog->iBottomMargin = iMargin;
42
pDialog->iMinBottomGap = MAX (20, myConfig.iCurlyRadius);
43
pDialog->iMinFrameWidth = 10; // au pif.
45
pDialog->fReflectAlpha = 0.;
49
void cd_decorator_draw_decorations_curly (cairo_t *pCairoContext, CairoDialog *pDialog) {
50
double fLineWidth = myConfig.iCurlyLineWidth;
51
double fRadius = myConfig.iCurlyRadius;
52
double fTipHeight = MIN (pDialog->iDistanceToDock, 20); // on completera par un trait.
53
double dh = MAX (1, myConfig.fCurlyCurvature * fTipHeight);
55
double fOffsetX = fRadius + fLineWidth / 2;
56
double fOffsetY = (pDialog->bDirectionUp ? fLineWidth / 2 : pDialog->iHeight - fLineWidth / 2);
57
int sens = (pDialog->bDirectionUp ? 1 : -1);
58
double fDemiWidth = .5 * pDialog->iWidth - fRadius - fLineWidth/2;
60
//On se déplace la ou il le faut
61
cairo_move_to (pCairoContext, fOffsetX, fOffsetY);
62
cairo_set_tolerance (pCairoContext, 0.33);
64
// Ligne du haut (Haut gauche -> Haut Droite)
65
///cairo_rel_line_to (pCairoContext, iWidth - (2 * fRadius + fLineWidth), 0);
66
cairo_rel_curve_to (pCairoContext,
68
fDemiWidth/2, sens * pDialog->iTopMargin,
69
fDemiWidth, sens * pDialog->iTopMargin);
70
cairo_rel_curve_to (pCairoContext,
72
fDemiWidth/2, - sens * pDialog->iTopMargin,
73
fDemiWidth, - sens * pDialog->iTopMargin);
76
cairo_rel_curve_to (pCairoContext,
79
fRadius, sens * fRadius);
81
// Ligne droite. (Haut droit -> Bas droit)
82
double fDemiHeight = .5 * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (fRadius + fLineWidth/2));
83
cairo_rel_curve_to (pCairoContext,
84
0, sens * fDemiHeight/2,
85
- .5 * pDialog->iRightMargin, sens * fDemiHeight/2,
86
- .5 * pDialog->iRightMargin, sens * fDemiHeight);
87
cairo_rel_curve_to (pCairoContext,
88
0, sens * fDemiHeight/2,
89
.5 * pDialog->iRightMargin, sens * fDemiHeight/2,
90
.5 * pDialog->iRightMargin, sens * fDemiHeight);
91
///cairo_rel_line_to (pCairoContext, 0, sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
93
fDemiWidth = .5 * pDialog->iWidth - fLineWidth/2;
94
// Coin bas droit et pointe.
95
cairo_rel_curve_to (pCairoContext,
97
- fDemiWidth, sens * (fTipHeight - dh),
98
- fDemiWidth, sens * fTipHeight);
100
// Coin bas gauche et pointe.
101
cairo_rel_curve_to (pCairoContext,
103
- fDemiWidth, - sens * (fTipHeight - dh),
104
- fDemiWidth, - sens * fTipHeight);
106
// On remonte par la gauche.
107
///cairo_rel_line_to (pCairoContext, 0, - sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
108
cairo_rel_curve_to (pCairoContext,
109
0, - sens * fDemiHeight/2,
110
.5 * pDialog->iRightMargin, - sens * fDemiHeight/2,
111
.5 * pDialog->iRightMargin, - sens * fDemiHeight);
112
cairo_rel_curve_to (pCairoContext,
113
0, - sens * fDemiHeight/2,
114
- .5 * pDialog->iRightMargin, - sens * fDemiHeight/2,
115
- .5 * pDialog->iRightMargin, - sens * fDemiHeight);
118
cairo_rel_curve_to (pCairoContext,
121
fRadius, -sens * fRadius);
123
cairo_close_path (pCairoContext);
125
// On remplit le fond.
126
cairo_set_source_rgba (pCairoContext, myDialogs.fDialogColor[0], myDialogs.fDialogColor[1], myDialogs.fDialogColor[2], myDialogs.fDialogColor[3]);
127
cairo_fill_preserve (pCairoContext);
129
// On trace le contour.
130
cairo_set_source_rgba (pCairoContext, myConfig.fCurlyLineColor[0], myConfig.fCurlyLineColor[1], myConfig.fCurlyLineColor[2], myConfig.fCurlyLineColor[3]);
131
cairo_set_line_width (pCairoContext, fLineWidth);
132
cairo_stroke (pCairoContext);
134
if (fTipHeight < pDialog->iDistanceToDock) // on descend jusqu'a l'icone.
136
double fGap = pDialog->iDistanceToDock - fTipHeight;
137
cairo_move_to (pCairoContext,
139
pDialog->bDirectionUp ? pDialog->iHeight - fGap : fGap);
140
cairo_rel_line_to (pCairoContext, 0, sens * fGap);
141
cairo_stroke (pCairoContext);
146
void cd_decorator_register_curly (void)
148
CairoDialogDecorator *pDecorator = g_new (CairoDialogDecorator, 1);
149
pDecorator->set_size = cd_decorator_set_frame_size_curly;
150
pDecorator->render = cd_decorator_draw_decorations_curly;
151
pDecorator->render_opengl = NULL;
152
pDecorator->cDisplayedName = D_ (MY_APPLET_DECORATOR_CURLY_NAME);
153
cairo_dock_register_dialog_decorator (MY_APPLET_DECORATOR_CURLY_NAME, pDecorator);