4
* This file is a part of the Cairo-Dock project
6
* Copyright : (C) see the 'copyright' file.
7
* E-mail : see the 'copyright' file.
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 3
12
* of the License, or (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
#include <cairo-dock.h>
26
#include "applet-struct.h"
27
#include "applet-decorator-comics.h"
29
#define CAIRO_DIALOG_MIN_GAP 20
30
#define CD_TIP_INNER_MARGIN 12
31
#define CD_TIP_OUTER_MARGIN 25
32
#define CD_TIP_BASE 25
33
#define _CAIRO_DIALOG_COMICS_MARGIN 4
35
void cd_decorator_set_frame_size_comics (CairoDialog *pDialog)
37
int iMargin = .5 * myConfig.iComicsLineWidth + (1. - sqrt (2) / 2) * myConfig.iComicsRadius + _CAIRO_DIALOG_COMICS_MARGIN; // on laisse qques pixels d'espace en plus tout autour.
38
g_print ("iMargin : %d\n", iMargin);
39
pDialog->iRightMargin = iMargin;
40
pDialog->iLeftMargin = iMargin;
41
pDialog->iTopMargin = iMargin;
42
pDialog->iBottomMargin = iMargin;
43
pDialog->iMinBottomGap = CAIRO_DIALOG_MIN_GAP;
44
pDialog->iMinFrameWidth = CD_TIP_OUTER_MARGIN + CD_TIP_BASE + CD_TIP_INNER_MARGIN + 2*iMargin;
45
pDialog->fAlign = 0.; // la pointe colle au bord du dialogue.
46
pDialog->container.fRatio = 0.; // pas de reflet merci.
47
pDialog->container.bUseReflect = FALSE;
50
void cd_decorator_draw_decorations_comics (cairo_t *pCairoContext, CairoDialog *pDialog)
52
double fLineWidth = myConfig.iComicsLineWidth;
53
double fRadius = MIN (myConfig.iComicsRadius, pDialog->iBubbleHeight/2 - fLineWidth);
55
/**double fGapFromDock = pDialog->iMinBottomGap + pDialog->iBottomMargin + fLineWidth/2;
56
double cos_gamma = 1 / sqrt (1. + 1. * (CAIRO_DIALOG_TIP_MARGIN + CD_TIP_BASE) / fGapFromDock * (CAIRO_DIALOG_TIP_MARGIN + CD_TIP_BASE) / fGapFromDock);
57
double cos_theta = 1 / sqrt (1. + 1. * CAIRO_DIALOG_TIP_MARGIN / fGapFromDock * CAIRO_DIALOG_TIP_MARGIN / fGapFromDock);
58
double fTipHeight = fGapFromDock / (1. + fLineWidth / 2. / CD_TIP_BASE * (1./cos_gamma + 1./cos_theta));*/
59
//g_print ("TipHeight <- %d\n", (int)fTipHeight);
60
double fTipHeight = pDialog->iMinBottomGap;
62
int iWidth = pDialog->container.iWidth;
63
double fMargin = 2 * fRadius + fLineWidth;
64
double fBaseWidth = iWidth - fMargin;
65
double fTipWidth = CD_TIP_OUTER_MARGIN + CD_TIP_BASE + CD_TIP_INNER_MARGIN;
66
double fOffsetX = fRadius + fLineWidth / 2;
67
double fOffsetY = fLineWidth / 2;
70
if (!pDialog->container.bDirectionUp) // dessin a l'envers.
72
cairo_scale (pCairoContext, 1., -1.);
73
cairo_translate (pCairoContext, 0., -pDialog->container.iHeight);
75
cairo_move_to (pCairoContext, fOffsetX, fOffsetY);
77
cairo_rel_line_to (pCairoContext, fBaseWidth, 0);
79
cairo_rel_curve_to (pCairoContext,
83
cairo_rel_line_to (pCairoContext, 0, pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - fMargin);
85
cairo_rel_curve_to (pCairoContext,
92
bRight = (pDialog->container.iWindowPositionX + iWidth > pDialog->iAimedX + fTipWidth);
94
bRight = (pDialog->container.iWindowPositionX + fTipWidth > pDialog->iAimedX);
95
g_print ("%d, %d, %d -> %d\n", pDialog->container.iWindowPositionX, (int) fTipWidth, pDialog->iAimedX, bRight);
97
if (bRight) // dialogue a droite de l'icone, pointe vers la gauche.
99
iDeltaIconX = MIN (0, pDialog->container.iWindowPositionX - pDialog->iAimedX); // < 0
100
g_print ("iDeltaIconX right : %d / %d\n", iDeltaIconX, iWidth);
101
cairo_rel_line_to (pCairoContext, -(fBaseWidth + iDeltaIconX - fTipWidth), 0);
102
cairo_rel_curve_to (pCairoContext,
103
- CD_TIP_OUTER_MARGIN, 0,
104
- CD_TIP_OUTER_MARGIN, 0,
105
- fTipWidth, fTipHeight);
106
cairo_rel_curve_to (pCairoContext,
107
CD_TIP_INNER_MARGIN, - fTipHeight,
108
CD_TIP_INNER_MARGIN, - fTipHeight,
110
cairo_rel_line_to (pCairoContext, iDeltaIconX, 0);
112
else // dialogue a gauche de l'icone, pointe vers la droite.
114
iDeltaIconX = MAX (0, pDialog->container.iWindowPositionX + iWidth - pDialog->iAimedX); // > 0
115
g_print ("iDeltaIconX left : %d / %d\n", iDeltaIconX, iWidth);
116
cairo_rel_line_to (pCairoContext, - iDeltaIconX, 0);
117
cairo_rel_curve_to (pCairoContext,
118
- (CD_TIP_INNER_MARGIN), 0,
119
- (CD_TIP_INNER_MARGIN), 0,
121
cairo_rel_curve_to (pCairoContext,
122
- (CD_TIP_INNER_MARGIN + CD_TIP_BASE), - fTipHeight,
123
- (CD_TIP_INNER_MARGIN + CD_TIP_BASE), - fTipHeight,
124
- fTipWidth, - fTipHeight);
125
cairo_rel_line_to (pCairoContext, - fBaseWidth + iDeltaIconX + fTipWidth, 0);
129
cairo_rel_curve_to (pCairoContext,
133
cairo_rel_line_to (pCairoContext, 0, - (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - fMargin));
135
cairo_rel_curve_to (pCairoContext,
140
cairo_close_path (pCairoContext);
142
cairo_set_source_rgba (pCairoContext, myDialogs.fDialogColor[0], myDialogs.fDialogColor[1], myDialogs.fDialogColor[2], myDialogs.fDialogColor[3]);
143
cairo_fill_preserve (pCairoContext);
145
cairo_set_line_width (pCairoContext, fLineWidth);
146
cairo_set_source_rgba (pCairoContext, myConfig.fComicsLineColor[0], myConfig.fComicsLineColor[1], myConfig.fComicsLineColor[2], myConfig.fComicsLineColor[3]);
147
cairo_stroke (pCairoContext);
151
void cd_decorator_register_comics (void)
153
CairoDialogDecorator *pDecorator = g_new (CairoDialogDecorator, 1);
154
pDecorator->set_size = cd_decorator_set_frame_size_comics;
155
pDecorator->render = cd_decorator_draw_decorations_comics;
156
pDecorator->render_opengl = NULL;
157
pDecorator->cDisplayedName = D_ (MY_APPLET_DECORATOR_COMICS_NAME);
158
cairo_dock_register_dialog_decorator (MY_APPLET_DECORATOR_COMICS_NAME, pDecorator);