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

« back to all changes in this revision

Viewing changes to dialog-rendering/src/applet-decorator-comics.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-comics.h"
 
34
 
 
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
 
39
 
 
40
 
 
41
void cd_decorator_set_frame_size_comics (CairoDialog *pDialog)
 
42
{
 
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.
 
52
}
 
53
 
 
54
void cd_decorator_draw_decorations_comics (cairo_t *pCairoContext, CairoDialog *pDialog)
 
55
{
 
56
        double fLineWidth = myConfig.iComicsLineWidth;
 
57
        double fRadius = myConfig.iComicsRadius;
 
58
        
 
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);
 
64
 
 
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;
 
71
 
 
72
        cairo_rel_line_to (pCairoContext, iWidth - (2 * fRadius + fLineWidth), 0);
 
73
        // Coin haut droit.
 
74
        cairo_rel_curve_to (pCairoContext,
 
75
                0, 0,
 
76
                fRadius, 0,
 
77
                fRadius, sens * fRadius);
 
78
        cairo_rel_line_to (pCairoContext, 0, sens *     (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
 
79
        // Coin bas     droit.
 
80
        cairo_rel_curve_to (pCairoContext,
 
81
                0, 0,
 
82
                0, sens * fRadius,
 
83
                -fRadius, sens * fRadius);
 
84
        // La pointe.
 
85
        double fDeltaMargin;
 
86
        if (pDialog->bRight)
 
87
        {
 
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,
 
92
                        0, 0,
 
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,
 
96
                        0, 0,
 
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);
 
100
        }
 
101
        else
 
102
        {
 
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,
 
107
                        0, 0,
 
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,
 
111
                        0, 0,
 
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);
 
115
        }
 
116
 
 
117
        // Coin bas     gauche.
 
118
        cairo_rel_curve_to (pCairoContext,
 
119
                0, 0,
 
120
                -fRadius, 0,
 
121
                -fRadius, -sens * fRadius);
 
122
        cairo_rel_line_to (pCairoContext, 0, - sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
 
123
        // Coin haut gauche.
 
124
        cairo_rel_curve_to (pCairoContext,
 
125
                0, 0,
 
126
                0, -sens * fRadius,
 
127
                fRadius, -sens * fRadius);
 
128
        if (fRadius     < 1)
 
129
                cairo_close_path (pCairoContext);
 
130
 
 
131
        cairo_set_source_rgba (pCairoContext, myDialogs.fDialogColor[0], myDialogs.fDialogColor[1],     myDialogs.fDialogColor[2], myDialogs.fDialogColor[3]);
 
132
        cairo_fill_preserve (pCairoContext);
 
133
 
 
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);
 
137
}
 
138
 
 
139
 
 
140
void cd_decorator_register_comics (void)
 
141
{
 
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);
 
148
}