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-comics.h"
35
#define CAIRO_DIALOG_MIN_GAP 20
36
#define CAIRO_DIALOG_TIP_ROUNDING_MARGIN 12
37
#define CAIRO_DIALOG_TIP_MARGIN 25
38
#define CAIRO_DIALOG_TIP_BASE 25
41
void cd_decorator_set_frame_size_comics (CairoDialog *pDialog)
43
int iMargin = .5 * myConfig.iComicsLineWidth + (1. - sqrt (2) / 2) * myConfig.iComicsRadius;
44
pDialog->iRightMargin = iMargin;
45
pDialog->iLeftMargin = iMargin;
46
pDialog->iTopMargin = iMargin;
47
pDialog->iBottomMargin = iMargin;
48
pDialog->iMinBottomGap = CAIRO_DIALOG_MIN_GAP;
49
pDialog->iMinFrameWidth = CAIRO_DIALOG_TIP_MARGIN + CAIRO_DIALOG_TIP_ROUNDING_MARGIN + CAIRO_DIALOG_TIP_BASE; // dans l'ordre.
50
pDialog->fAlign = 0.; // la pointe colle au bord du dialogue.
51
pDialog->fReflectAlpha = 0.; // pas de reflet merci.
54
void cd_decorator_draw_decorations_comics (cairo_t *pCairoContext, CairoDialog *pDialog)
56
double fLineWidth = myConfig.iComicsLineWidth;
57
double fRadius = myConfig.iComicsRadius;
59
double fGapFromDock = pDialog->iDistanceToDock + .5 * fLineWidth;
60
double cos_gamma = 1 / sqrt (1. + 1. * (CAIRO_DIALOG_TIP_MARGIN + CAIRO_DIALOG_TIP_BASE) / fGapFromDock * (CAIRO_DIALOG_TIP_MARGIN + CAIRO_DIALOG_TIP_BASE) / fGapFromDock);
61
double cos_theta = 1 / sqrt (1. + 1. * CAIRO_DIALOG_TIP_MARGIN / fGapFromDock * CAIRO_DIALOG_TIP_MARGIN / fGapFromDock);
62
double fTipHeight = fGapFromDock / (1. + fLineWidth / 2. / CAIRO_DIALOG_TIP_BASE * (1./cos_gamma + 1./cos_theta));
63
//g_print ("TipHeight <- %d\n", (int)fTipHeight);
65
double fOffsetX = fRadius + fLineWidth / 2;
66
double fOffsetY = (pDialog->bDirectionUp ? fLineWidth / 2 : pDialog->iHeight - fLineWidth / 2);
67
int sens = (pDialog->bDirectionUp ? 1 : -1);
68
cairo_move_to (pCairoContext, fOffsetX, fOffsetY);
69
//g_print (" fOffsetX : %.2f; fOffsetY : %.2f\n", fOffsetX, fOffsetY);
70
int iWidth = pDialog->iWidth;
72
cairo_rel_line_to (pCairoContext, iWidth - (2 * fRadius + fLineWidth), 0);
74
cairo_rel_curve_to (pCairoContext,
77
fRadius, sens * fRadius);
78
cairo_rel_line_to (pCairoContext, 0, sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
80
cairo_rel_curve_to (pCairoContext,
83
-fRadius, sens * fRadius);
88
fDeltaMargin = MAX (0, pDialog->iAimedX - pDialog->iPositionX - fRadius - fLineWidth / 2);
89
//g_print ("fDeltaMargin : %.2f\n", fDeltaMargin);
90
cairo_rel_line_to (pCairoContext, -iWidth + fDeltaMargin + fLineWidth + 2 * fRadius + CAIRO_DIALOG_TIP_MARGIN + CAIRO_DIALOG_TIP_BASE + CAIRO_DIALOG_TIP_ROUNDING_MARGIN , 0);
91
cairo_rel_curve_to (pCairoContext,
93
- CAIRO_DIALOG_TIP_ROUNDING_MARGIN, 0,
94
- (CAIRO_DIALOG_TIP_ROUNDING_MARGIN + CAIRO_DIALOG_TIP_MARGIN + CAIRO_DIALOG_TIP_BASE), sens * fTipHeight);
95
cairo_rel_curve_to (pCairoContext,
97
CAIRO_DIALOG_TIP_MARGIN, - sens * fTipHeight,
98
CAIRO_DIALOG_TIP_MARGIN - CAIRO_DIALOG_TIP_ROUNDING_MARGIN, - sens * fTipHeight);
99
cairo_rel_line_to (pCairoContext, - CAIRO_DIALOG_TIP_MARGIN - fDeltaMargin + CAIRO_DIALOG_TIP_ROUNDING_MARGIN, 0);
103
fDeltaMargin = MAX (0, MIN (- CAIRO_DIALOG_TIP_MARGIN - CAIRO_DIALOG_TIP_ROUNDING_MARGIN - CAIRO_DIALOG_TIP_BASE - fRadius - fLineWidth / 2, pDialog->iPositionX - pDialog->iAimedX - fRadius - fLineWidth / 2) + pDialog->iWidth);
104
//g_print ("fDeltaMargin : %.2f / %d\n", fDeltaMargin, pDialog->iWidth);
105
cairo_rel_line_to (pCairoContext, - (CAIRO_DIALOG_TIP_MARGIN + fDeltaMargin) + CAIRO_DIALOG_TIP_ROUNDING_MARGIN, 0);
106
cairo_rel_curve_to (pCairoContext,
108
-CAIRO_DIALOG_TIP_ROUNDING_MARGIN, 0,
109
CAIRO_DIALOG_TIP_MARGIN - CAIRO_DIALOG_TIP_ROUNDING_MARGIN, sens * fTipHeight);
110
cairo_rel_curve_to (pCairoContext,
112
- (CAIRO_DIALOG_TIP_MARGIN + CAIRO_DIALOG_TIP_BASE), - sens * fTipHeight,
113
- (CAIRO_DIALOG_TIP_MARGIN + CAIRO_DIALOG_TIP_BASE) - CAIRO_DIALOG_TIP_ROUNDING_MARGIN, - sens * fTipHeight);
114
cairo_rel_line_to (pCairoContext, -iWidth + fDeltaMargin + fLineWidth + 2 * fRadius + CAIRO_DIALOG_TIP_MARGIN + CAIRO_DIALOG_TIP_BASE + CAIRO_DIALOG_TIP_ROUNDING_MARGIN, 0);
118
cairo_rel_curve_to (pCairoContext,
121
-fRadius, -sens * fRadius);
122
cairo_rel_line_to (pCairoContext, 0, - sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
124
cairo_rel_curve_to (pCairoContext,
127
fRadius, -sens * fRadius);
129
cairo_close_path (pCairoContext);
131
cairo_set_source_rgba (pCairoContext, myDialogs.fDialogColor[0], myDialogs.fDialogColor[1], myDialogs.fDialogColor[2], myDialogs.fDialogColor[3]);
132
cairo_fill_preserve (pCairoContext);
134
cairo_set_line_width (pCairoContext, fLineWidth);
135
cairo_set_source_rgba (pCairoContext, myConfig.fComicsLineColor[0], myConfig.fComicsLineColor[1], myConfig.fComicsLineColor[2], myConfig.fComicsLineColor[3]);
136
cairo_stroke (pCairoContext);
140
void cd_decorator_register_comics (void)
142
CairoDialogDecorator *pDecorator = g_new (CairoDialogDecorator, 1);
143
pDecorator->set_size = cd_decorator_set_frame_size_comics;
144
pDecorator->render = cd_decorator_draw_decorations_comics;
145
pDecorator->render_opengl = NULL;
146
pDecorator->cDisplayedName = D_ (MY_APPLET_DECORATOR_COMICS_NAME);
147
cairo_dock_register_dialog_decorator (MY_APPLET_DECORATOR_COMICS_NAME, pDecorator);