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

« back to all changes in this revision

Viewing changes to dialog-rendering/src/applet-decorator-tooltip.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 ChanGFu (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-tooltip.h"
 
34
 
 
35
//A bosser
 
36
#define _CAIRO_DIALOG_TOOLTIP_MIN_GAP 10
 
37
#define _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH 20
 
38
#define _CAIRO_DIALOG_TOOLTIP_ARROW_HEIGHT 5
 
39
 
 
40
 
 
41
void cd_decorator_set_frame_size_tooltip (CairoDialog *pDialog) {
 
42
        int iMargin = .5 * myConfig.iTooltipLineWidth + (1. - sqrt (2) / 2) * myConfig.iTooltipRadius;
 
43
        pDialog->iRightMargin = iMargin;
 
44
        pDialog->iLeftMargin = iMargin;
 
45
        pDialog->iTopMargin = 0;
 
46
        pDialog->iBottomMargin = 0;
 
47
        pDialog->iMinBottomGap = _CAIRO_DIALOG_TOOLTIP_MIN_GAP;
 
48
        pDialog->iMinFrameWidth = _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH;
 
49
        pDialog->fAlign = .5;
 
50
        pDialog->fReflectAlpha = 0.;
 
51
}
 
52
 
 
53
 
 
54
void cd_decorator_draw_decorations_tooltip (cairo_t *pCairoContext, CairoDialog *pDialog) {
 
55
        double fLineWidth = myConfig.iTooltipLineWidth;
 
56
        double fRadius = myConfig.iTooltipRadius;
 
57
        
 
58
        double fOffsetX = fRadius + fLineWidth / 2;
 
59
        double fOffsetY = (pDialog->bDirectionUp ? fLineWidth / 2 : pDialog->iHeight - fLineWidth / 2);
 
60
        int sens = (pDialog->bDirectionUp ? 1 : -1);
 
61
        int iWidth = pDialog->iWidth;
 
62
        
 
63
        //On se déplace la ou il le faut
 
64
        cairo_move_to (pCairoContext, fOffsetX, fOffsetY);
 
65
        
 
66
        // Ligne du haut (Haut gauche -> Haut Droite)
 
67
        cairo_rel_line_to (pCairoContext, iWidth - (2 * fRadius + fLineWidth), 0);
 
68
        
 
69
        // Coin haut droit.
 
70
        cairo_rel_curve_to (pCairoContext,
 
71
        0, 0,
 
72
        fRadius, 0,
 
73
        fRadius, sens * fRadius);
 
74
        
 
75
        // Ligne droite. (Haut droit -> Bas droit)
 
76
        cairo_rel_line_to (pCairoContext, 0, sens *     (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
 
77
        
 
78
        // Coin bas droit.
 
79
        cairo_rel_curve_to (pCairoContext,
 
80
        0, 0,
 
81
        0, sens * fRadius,
 
82
        -fRadius, sens * fRadius);
 
83
        
 
84
        // La pointe.
 
85
        double fDemiWidth = (iWidth - fLineWidth - 2 * fRadius - _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH)/2;
 
86
        cairo_rel_line_to (pCairoContext, -fDemiWidth,   0);
 
87
        cairo_rel_line_to (pCairoContext, - _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH/2, sens * _CAIRO_DIALOG_TOOLTIP_ARROW_HEIGHT);
 
88
        cairo_rel_line_to (pCairoContext, - _CAIRO_DIALOG_TOOLTIP_ARROW_WIDTH/2, -sens * _CAIRO_DIALOG_TOOLTIP_ARROW_HEIGHT);
 
89
        cairo_rel_line_to (pCairoContext, - fDemiWidth, 0);
 
90
        
 
91
        // Coin bas gauche.
 
92
        cairo_rel_curve_to (pCairoContext,
 
93
                0, 0,
 
94
                -fRadius, 0,
 
95
                -fRadius, -sens * fRadius);
 
96
        
 
97
        // On remonte.
 
98
        cairo_rel_line_to (pCairoContext, 0, - sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + fLineWidth)));
 
99
        
 
100
        // Coin haut gauche.
 
101
        cairo_rel_curve_to (pCairoContext,
 
102
                0, 0,
 
103
                0, -sens * fRadius,
 
104
                fRadius, -sens * fRadius);
 
105
        if (fRadius     < 1)
 
106
                cairo_close_path (pCairoContext);
 
107
        
 
108
        cairo_set_source_rgba (pCairoContext, myDialogs.fDialogColor[0], myDialogs.fDialogColor[1],     myDialogs.fDialogColor[2], myDialogs.fDialogColor[3]);
 
109
        cairo_fill_preserve (pCairoContext); //Notre fond
 
110
        cairo_set_source_rgba (pCairoContext, myConfig.fTooltipLineColor[0], myConfig.fTooltipLineColor[1], myConfig.fTooltipLineColor[2], myConfig.fTooltipLineColor[3]);
 
111
        cairo_set_line_width (pCairoContext, fLineWidth); //La ligne externe
 
112
        
 
113
        cairo_stroke (pCairoContext); //On ferme notre chemin
 
114
        
 
115
        if (pDialog->iIconSize != 0) {
 
116
                //Ajout d'un cadre pour l'icône (Pas d'alpha)
 
117
                int iIconFrameWidth = (pDialog->iIconSize / 2) - (2 * fRadius + fLineWidth);
 
118
                //cd_debug ("Tooltip: %d", iIconFrameWidth);
 
119
                //cairo_move_to (pCairoContext, 0, 0); //On revient a l'origine
 
120
                cairo_move_to (pCairoContext, fOffsetX + 2 * (fLineWidth + 1), fOffsetY + 2 * (fLineWidth + 1)); //Pour créer l'effet d'inclusion
 
121
                //On trace une ligne HautGauche -> HautDroit
 
122
                cairo_rel_line_to (pCairoContext, iIconFrameWidth, 0);
 
123
                //On trace une ligne HautDroit -> BasDroit
 
124
                cairo_rel_line_to (pCairoContext, 0, sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (fRadius + fLineWidth)));
 
125
                //On trace une ligne BasDroit -> BasGauche
 
126
                cairo_rel_line_to (pCairoContext, - iIconFrameWidth, 0);
 
127
                // Coin bas     gauche.
 
128
                cairo_rel_curve_to (pCairoContext,
 
129
                        0, 0,
 
130
                        -fRadius, 0,
 
131
                        -fRadius, -sens * fRadius);
 
132
                //On trace une ligne BasGauche -> HautGauche
 
133
                cairo_rel_line_to (pCairoContext, 0, - sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (2 * fRadius + 2 * (fLineWidth + 3.5))));
 
134
                
 
135
                // Coin haut gauche.
 
136
                cairo_rel_curve_to (pCairoContext,
 
137
                        0, 0,
 
138
                        0, -sens * fRadius,
 
139
                        fRadius, -sens * fRadius);
 
140
                
 
141
                if (fRadius < 1)
 
142
                        cairo_close_path (pCairoContext);
 
143
                
 
144
                cairo_set_source_rgba (pCairoContext, myConfig.fTooltipMarginColor[0], myConfig.fTooltipMarginColor[1],  myConfig.fTooltipMarginColor[2], myConfig.fTooltipMarginColor[3]);
 
145
                cairo_fill_preserve (pCairoContext);
 
146
                cairo_set_source_rgba (pCairoContext, myConfig.fTooltipLineColor[0], myConfig.fTooltipLineColor[1], myConfig.fTooltipLineColor[2], myConfig.fTooltipLineColor[3]);
 
147
                cairo_set_line_width (pCairoContext, fLineWidth);
 
148
                
 
149
                cairo_stroke (pCairoContext);
 
150
        }
 
151
}
 
152
 
 
153
 
 
154
void cd_decorator_register_tooltip (void)
 
155
{
 
156
        CairoDialogDecorator *pDecorator = g_new (CairoDialogDecorator, 1);
 
157
        pDecorator->set_size = cd_decorator_set_frame_size_tooltip;
 
158
        pDecorator->render = cd_decorator_draw_decorations_tooltip;
 
159
        pDecorator->render_opengl = NULL;
 
160
        pDecorator->cDisplayedName = D_ (MY_APPLET_DECORATOR_TOOLTIP_NAME);
 
161
        cairo_dock_register_dialog_decorator (MY_APPLET_DECORATOR_TOOLTIP_NAME, pDecorator);
 
162
}