~ubuntu-branches/ubuntu/oneiric/cairo-dock-plug-ins/oneiric-updates

« back to all changes in this revision

Viewing changes to dialog-rendering/src/applet-decorator-modern.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-modern.h"
 
34
 
 
35
 
 
36
void cd_decorator_set_frame_size_modern (CairoDialog *pDialog)
 
37
{
 
38
        int iMargin = .5 * myConfig.iModernLineWidth + .5 * myConfig.iModernRadius;
 
39
        pDialog->iRightMargin = iMargin;
 
40
        pDialog->iLeftMargin = iMargin;
 
41
        pDialog->iTopMargin = iMargin;
 
42
        pDialog->iBottomMargin = iMargin;
 
43
        pDialog->iMinBottomGap = 30;
 
44
        pDialog->iMinFrameWidth = 30;  // valeur au pif.
 
45
        pDialog->fAlign = .33;  // la pointe est a 33% du bord du dialogue.
 
46
        pDialog->fReflectAlpha = 0.;  // pas de reflet merci.
 
47
}
 
48
 
 
49
 
 
50
void cd_decorator_draw_decorations_modern (cairo_t *pCairoContext, CairoDialog *pDialog)
 
51
{
 
52
        double fLineWidth = myConfig.iModernLineWidth;
 
53
        double fRadius = MIN (myConfig.iModernRadius, pDialog->iBubbleHeight/2);
 
54
        int sens = (pDialog->bDirectionUp ?     1 :     -1);
 
55
        int sens2 = (pDialog->bRight ? 1 :      -1);
 
56
        
 
57
        //\_________________ On part du haut.
 
58
        double fOffsetX = (pDialog->bRight ? fLineWidth/2 : pDialog->iWidth - fLineWidth/2);
 
59
        double fOffsetY = (pDialog->bDirectionUp ? 0. : pDialog->iHeight);
 
60
        cairo_move_to (pCairoContext, fOffsetX, fOffsetY);
 
61
        
 
62
        //\_________________ On remplit le fond.
 
63
        cairo_rel_line_to (pCairoContext,
 
64
                0.,
 
65
                sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - fRadius));
 
66
        cairo_rel_line_to (pCairoContext,
 
67
                sens2 * fRadius,
 
68
                sens * fRadius);
 
69
        cairo_rel_line_to (pCairoContext,
 
70
                sens2 * pDialog->iBubbleWidth,
 
71
                0.);
 
72
        cairo_set_line_width (pCairoContext, fLineWidth);
 
73
        cairo_set_source_rgba (pCairoContext, myConfig.fModernLineColor[0], myConfig.fModernLineColor[1], myConfig.fModernLineColor[2], myConfig.fModernLineColor[3]);
 
74
        
 
75
        cairo_rel_line_to (pCairoContext,
 
76
                0.,
 
77
                - sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - fRadius));
 
78
        cairo_rel_line_to (pCairoContext,
 
79
                - sens2 * fRadius,
 
80
                - sens * fRadius);
 
81
        cairo_close_path (pCairoContext);
 
82
        cairo_set_source_rgba (pCairoContext, myDialogs.fDialogColor[0], myDialogs.fDialogColor[1],     myDialogs.fDialogColor[2], myDialogs.fDialogColor[3]);
 
83
        cairo_fill (pCairoContext);
 
84
        
 
85
        //\_________________ On trace le cadre.
 
86
        cairo_move_to (pCairoContext, fOffsetX, fOffsetY);
 
87
        cairo_rel_line_to (pCairoContext,
 
88
                0.,
 
89
                sens * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - fRadius));
 
90
        cairo_rel_line_to (pCairoContext,
 
91
                sens2 * fRadius,
 
92
                sens * fRadius);
 
93
        cairo_rel_line_to (pCairoContext,
 
94
                sens2 * pDialog->iBubbleWidth,
 
95
                0.);
 
96
        cairo_set_line_width (pCairoContext, fLineWidth);
 
97
        cairo_set_source_rgba (pCairoContext, myConfig.fModernLineColor[0], myConfig.fModernLineColor[1], myConfig.fModernLineColor[2], myConfig.fModernLineColor[3]);
 
98
        cairo_stroke (pCairoContext);
 
99
        
 
100
        //\_________________ On part du haut, petit cote.
 
101
        fOffsetX = (pDialog->bRight ? fRadius + fLineWidth/2 : pDialog->iWidth - fRadius - fLineWidth/2);
 
102
        fOffsetY = (pDialog->bDirectionUp ? pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin : pDialog->iHeight - (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin));
 
103
        
 
104
        //\_________________ On trace la pointe.
 
105
        cairo_set_line_width (pCairoContext, 1.);
 
106
        cairo_set_source_rgba (pCairoContext, myConfig.fModernLineColor[0], myConfig.fModernLineColor[1], myConfig.fModernLineColor[2], myConfig.fModernLineColor[3]);
 
107
        int i, h = pDialog->iHeight - (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin);
 
108
        double w1 = MAX (0, pDialog->iAimedX - pDialog->iPositionX - (pDialog->bRight ? fOffsetX : 0));
 
109
        double w2 = MAX (0, pDialog->iPositionX + pDialog->iWidth - pDialog->iAimedX - (pDialog->bRight ? 0 : fRadius + fLineWidth/2));
 
110
        //g_print ("%.2f,%.2f ; %d + %d > %d\n", w1, w2, pDialog->iPositionX, pDialog->iWidth, pDialog->iAimedX);
 
111
        double x, y, w;
 
112
        for (i = 0; i < h; i += 4)
 
113
        {
 
114
                y = fOffsetY + sens * i;
 
115
                x = fOffsetX + 1. * sens2 * i / h * (pDialog->bRight ? w1 : w2);
 
116
                w = (w1 + w2) * (h - i) / h;
 
117
                cairo_move_to (pCairoContext, x, y);
 
118
                cairo_rel_line_to (pCairoContext,
 
119
                        sens2 * w,
 
120
                        0.);
 
121
                cairo_stroke (pCairoContext);
 
122
        }
 
123
        if (h-i > 1)
 
124
        {
 
125
                y = fOffsetY + sens * h;
 
126
                x = fOffsetX + 1. * sens2 * (pDialog->bRight ? w1 : w2);
 
127
                w = MIN (w/2, 15);
 
128
                cairo_move_to (pCairoContext, x, y);
 
129
                cairo_rel_line_to (pCairoContext,
 
130
                        sens2 * w,
 
131
                        0.);
 
132
                cairo_stroke (pCairoContext);
 
133
        }
 
134
}
 
135
 
 
136
 
 
137
void cd_decorator_register_modern (void)
 
138
{
 
139
        CairoDialogDecorator *pDecorator = g_new (CairoDialogDecorator, 1);
 
140
        pDecorator->set_size = cd_decorator_set_frame_size_modern;
 
141
        pDecorator->render = cd_decorator_draw_decorations_modern;
 
142
        pDecorator->render_opengl = NULL;
 
143
        pDecorator->cDisplayedName = D_ (MY_APPLET_DECORATOR_MODERN_NAME);
 
144
        cairo_dock_register_dialog_decorator (MY_APPLET_DECORATOR_MODERN_NAME, pDecorator);
 
145
}