~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to dialog-rendering/src/applet-decorator-curly.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
Import upstream version 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
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.
 
11
*
 
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/>.
 
18
*/
 
19
 
 
20
/*********************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
*********************************************************************************/
 
28
#include <string.h>
 
29
#include <math.h>
 
30
#include <cairo-dock.h>
 
31
 
 
32
#include "applet-struct.h"
 
33
#include "applet-decorator-curly.h"
 
34
 
 
35
 
 
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.
 
44
        pDialog->fAlign = .5;
 
45
        pDialog->fReflectAlpha = 0.;
 
46
}
 
47
 
 
48
 
 
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);
 
54
        
 
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;
 
59
        
 
60
        //On se déplace la ou il le faut
 
61
        cairo_move_to (pCairoContext, fOffsetX, fOffsetY);
 
62
        cairo_set_tolerance (pCairoContext, 0.33);
 
63
        
 
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,
 
67
                fDemiWidth/2, 0,
 
68
                fDemiWidth/2, sens * pDialog->iTopMargin,
 
69
                fDemiWidth, sens * pDialog->iTopMargin);
 
70
        cairo_rel_curve_to (pCairoContext,
 
71
                fDemiWidth/2, 0,
 
72
                fDemiWidth/2, - sens * pDialog->iTopMargin,
 
73
                fDemiWidth, - sens * pDialog->iTopMargin);
 
74
        
 
75
        // Coin haut droit.
 
76
        cairo_rel_curve_to (pCairoContext,
 
77
                0, 0,
 
78
                fRadius, 0,
 
79
                fRadius, sens * fRadius);
 
80
        
 
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)));
 
92
        
 
93
        fDemiWidth = .5 * pDialog->iWidth - fLineWidth/2;
 
94
        // Coin bas droit et pointe.
 
95
        cairo_rel_curve_to (pCairoContext,
 
96
                0, sens * dh,
 
97
                - fDemiWidth, sens * (fTipHeight - dh),
 
98
                - fDemiWidth, sens * fTipHeight);
 
99
        
 
100
        // Coin bas gauche et pointe.
 
101
        cairo_rel_curve_to (pCairoContext,
 
102
                0, - sens * dh,
 
103
                - fDemiWidth, - sens * (fTipHeight - dh),
 
104
                - fDemiWidth, - sens * fTipHeight);
 
105
        
 
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);
 
116
        
 
117
        // Coin haut gauche.
 
118
        cairo_rel_curve_to (pCairoContext,
 
119
                0, 0,
 
120
                0, -sens * fRadius,
 
121
                fRadius, -sens * fRadius);
 
122
        if (fRadius < 1)
 
123
                cairo_close_path (pCairoContext);
 
124
        
 
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);
 
128
        
 
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);
 
133
        
 
134
        if (fTipHeight < pDialog->iDistanceToDock)  // on descend jusqu'a l'icone.
 
135
        {
 
136
                double fGap = pDialog->iDistanceToDock - fTipHeight;
 
137
                cairo_move_to (pCairoContext,
 
138
                        pDialog->iWidth/2,
 
139
                        pDialog->bDirectionUp ? pDialog->iHeight - fGap : fGap);
 
140
                cairo_rel_line_to (pCairoContext, 0, sens * fGap);
 
141
                cairo_stroke (pCairoContext);
 
142
        }
 
143
}
 
144
 
 
145
 
 
146
void cd_decorator_register_curly (void)
 
147
{
 
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);
 
154
}