~noskcaj/ubuntu/utopic/cairo-dock-plug-ins/upower

« back to all changes in this revision

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

  • Committer: Matthieu Baerts
  • Date: 2014-02-19 23:22:46 UTC
  • mfrom: (1.1.36)
  • Revision ID: matttbe@gmail.com-20140219232246-iopf2zg7s6jby9tt
Tags: 3.3.99.beta1.1~20140219~bzr3061-0ubuntu1
* New upstream snapshot.
* Short Upstream ChangeLog:
  - All: updated due to recent API changes and changes in the global style
  - GMenu:
    - Do not create empty menus
    - Show the dialogue to open a new after after the end of the installation
    - Added an option to not show this dialogue
  - Gnome: support Cinnamon logout
  - Logout: display a message to reboot the system after the end of the update
  - Shortcut: improve the support of bookmarks
  - Status-Notifier: support scroll events
  - Terminal: open terminal on middle click
  - Some bugs have been fixed (LP: #1253654), other tweaks
* debian/control:
  - Bumped Cairo-Dock (core) versions
  - Bumped Standard Version (no change needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "applet-struct.h"
25
25
#include "applet-decorator-curly.h"
26
26
 
 
27
#define CD_ARROW_HEIGHT 12
 
28
#define CD_ALIGN 0.5
 
29
#define CD_RADIUS (myDialogsParam.bUseDefaultColors ? myStyleParam.iCornerRadius : myDialogsParam.iCornerRadius)
27
30
 
28
31
void cd_decorator_set_frame_size_curly (CairoDialog *pDialog)
29
32
{
30
 
        int iMargin = .5 * myConfig.iCurlyLineWidth + (1. - sqrt (2) / 2) * myConfig.iCurlyRadius;
 
33
        int iMargin = .5 * myDialogsParam.iLineWidth + (1. - sqrt (2) / 2) * CD_RADIUS;
31
34
        pDialog->iRightMargin = iMargin;
32
35
        pDialog->iLeftMargin = iMargin;
33
36
        pDialog->iTopMargin = iMargin;
34
 
        pDialog->iBottomMargin = 2*iMargin;
35
 
        pDialog->iMinBottomGap = MAX (20, 2*myConfig.iCurlyRadius);
 
37
        pDialog->iBottomMargin = iMargin;
 
38
        pDialog->iMinBottomGap = CD_ARROW_HEIGHT + CD_RADIUS;
36
39
        pDialog->iMinFrameWidth = 10;  // au pif.
37
40
        pDialog->fAlign = .5;
38
41
        pDialog->container.fRatio = 0.;
42
45
 
43
46
void cd_decorator_draw_decorations_curly (cairo_t *pCairoContext, CairoDialog *pDialog)
44
47
{
45
 
        double fLineWidth = myConfig.iCurlyLineWidth;
46
 
        double fRadius = myConfig.iCurlyRadius;
 
48
        double fLineWidth = myDialogsParam.iLineWidth;
 
49
        double fRadius = CD_RADIUS;
47
50
        // double fBottomRadius = 2 * fRadius;
48
 
        double fTipHeight = pDialog->iMinBottomGap + 0*pDialog->iBottomMargin + fLineWidth/2;
49
 
        double dh = MIN (MAX (1, myConfig.fCurlyCurvature * fTipHeight), .4 * pDialog->container.iWidth);
 
51
        double fTipHeight = pDialog->iMinBottomGap + fLineWidth/2;
 
52
        double dh = MIN (fTipHeight + fRadius, .3 * pDialog->container.iWidth);
50
53
        
51
54
        double fOffsetX = fRadius + fLineWidth / 2;
52
55
        double fOffsetY = (pDialog->container.bDirectionUp ? fLineWidth / 2 : pDialog->container.iHeight - fLineWidth / 2);
85
88
        cairo_set_tolerance (pCairoContext, 0.33);
86
89
        
87
90
        // Ligne du haut (Haut gauche -> Haut Droite)
88
 
        double fDeltaTop = MIN (pDialog->iTopMargin, .2 * fDemiWidth);
89
 
        cairo_rel_curve_to (pCairoContext,
90
 
                fDemiWidth/2, 0,
91
 
                fDemiWidth/2, sens * fDeltaTop,
92
 
                fDemiWidth, sens * fDeltaTop);
93
 
        cairo_rel_curve_to (pCairoContext,
94
 
                fDemiWidth/2, 0,
95
 
                fDemiWidth/2, - sens * fDeltaTop,
96
 
                fDemiWidth, - sens * fDeltaTop);
 
91
        cairo_rel_line_to (pCairoContext,
 
92
                2*fDemiWidth,
 
93
                0.);
97
94
        
98
95
        // Coin haut droit.
99
96
        cairo_rel_curve_to (pCairoContext,
102
99
                fRadius, sens * fRadius);
103
100
        
104
101
        // Ligne droite. (Haut droit -> Bas droit)
105
 
        double fDemiHeight = .5 * (pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (fRadius + fLineWidth/2));
106
 
        double fDeltaSide = MIN (pDialog->iRightMargin, .2 * fDemiHeight);
107
 
        if (myConfig.bCulrySideToo)
108
 
        {
109
 
                cairo_rel_curve_to (pCairoContext,
110
 
                        0, sens * fDemiHeight/2,
111
 
                        - .5 * fDeltaSide, sens * fDemiHeight/2,
112
 
                        - .5 * fDeltaSide, sens * fDemiHeight);
113
 
                cairo_rel_curve_to (pCairoContext,
114
 
                        0, sens * fDemiHeight/2,
115
 
                        .5 * fDeltaSide, sens * fDemiHeight/2,
116
 
                        .5 * fDeltaSide, sens * fDemiHeight);
117
 
        }
118
 
        else
119
 
        {
120
 
                cairo_rel_line_to (pCairoContext,
121
 
                        0,
122
 
                        sens * fDemiHeight * 2);
123
 
        }
 
102
        double fHeight = pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (fRadius + fLineWidth/2);
 
103
        cairo_rel_line_to (pCairoContext,
 
104
                0,
 
105
                sens * fHeight);
124
106
        
125
107
        fDemiWidth = .5 * pDialog->container.iWidth - fLineWidth/2;
126
108
        // Coin bas droit et pointe.
136
118
                - fDemiWidth - iDeltaIconX, - sens * fTipHeight);
137
119
        
138
120
        // On remonte par la gauche.
139
 
        if (myConfig.bCulrySideToo)
140
 
        {
141
 
                cairo_rel_curve_to (pCairoContext,
142
 
                        0, - sens * fDemiHeight/2,
143
 
                        .5 * fDeltaSide, - sens * fDemiHeight/2,
144
 
                        .5 * fDeltaSide, - sens * fDemiHeight);
145
 
                cairo_rel_curve_to (pCairoContext,
146
 
                        0, - sens * fDemiHeight/2,
147
 
                        - .5 * fDeltaSide, - sens * fDemiHeight/2,
148
 
                        - .5 * fDeltaSide, - sens * fDemiHeight);
149
 
        }
150
 
        else
151
 
        {
152
 
                cairo_rel_line_to (pCairoContext,
153
 
                        0,
154
 
                        - sens * fDemiHeight * 2);
155
 
        }
 
121
        cairo_rel_line_to (pCairoContext,
 
122
                0,
 
123
                - sens * fHeight);
156
124
        // Coin haut gauche.
157
125
        cairo_rel_curve_to (pCairoContext,
158
126
                0, 0,
162
130
                cairo_close_path (pCairoContext);
163
131
        
164
132
        // On remplit le fond.
165
 
        cairo_set_source_rgba (pCairoContext, myDialogsParam.fDialogColor[0], myDialogsParam.fDialogColor[1], myDialogsParam.fDialogColor[2], myDialogsParam.fDialogColor[3]);
166
 
        cairo_fill_preserve (pCairoContext);
 
133
        if (myDialogsParam.bUseDefaultColors)
 
134
                gldi_style_colors_set_bg_color (pCairoContext);
 
135
        else
 
136
                cairo_set_source_rgba (pCairoContext, myDialogsParam.fBgColor[0], myDialogsParam.fBgColor[1], myDialogsParam.fBgColor[2], myDialogsParam.fBgColor[3]);
 
137
        ///cairo_fill_preserve (pCairoContext);
 
138
        cairo_save (pCairoContext);
 
139
        cairo_clip_preserve (pCairoContext);
 
140
        gldi_style_colors_paint_bg_color (pCairoContext, pDialog->container.iWidth);
 
141
        cairo_restore (pCairoContext);
167
142
        
168
143
        // On trace le contour.
169
 
        cairo_set_source_rgba (pCairoContext, myConfig.fCurlyLineColor[0], myConfig.fCurlyLineColor[1], myConfig.fCurlyLineColor[2], myConfig.fCurlyLineColor[3]);
170
 
        cairo_set_line_width (pCairoContext, fLineWidth);
171
 
        cairo_stroke (pCairoContext);
172
 
}
173
 
 
 
144
        if (fLineWidth != 0)  // draw the outline with same color as bg, but opaque
 
145
        {
 
146
                if (myDialogsParam.bUseDefaultColors)
 
147
                        gldi_style_colors_set_line_color (pCairoContext);
 
148
                else
 
149
                        cairo_set_source_rgba (pCairoContext, myDialogsParam.fLineColor[0], myDialogsParam.fLineColor[1], myDialogsParam.fLineColor[2], myDialogsParam.fLineColor[3]);
 
150
                cairo_set_line_width (pCairoContext, fLineWidth);
 
151
                cairo_stroke (pCairoContext);
 
152
        }
 
153
}
 
154
 
 
155
 
 
156
static void _render_menu (GtkWidget *pMenu, cairo_t *pCairoContext)
 
157
{
 
158
        GldiMenuParams *pParams = g_object_get_data (G_OBJECT(pMenu), "gldi-params");
 
159
        int iMarginPosition = -1;
 
160
        int iAimedX = 0, iAimedY = 0;
 
161
        int ah = CD_ARROW_HEIGHT;
 
162
        if (pParams && pParams->pIcon)  // main menu
 
163
        {
 
164
                iMarginPosition = pParams->iMarginPosition;
 
165
                iAimedX = pParams->iAimedX;
 
166
                iAimedY = pParams->iAimedY;
 
167
        }
 
168
        
 
169
        // draw the outline and set the clip
 
170
        GtkAllocation alloc;
 
171
        gtk_widget_get_allocation (pMenu, &alloc);
 
172
        
 
173
        int w = alloc.width, h = alloc.height;
 
174
        int x, y;
 
175
        gdk_window_get_position (gtk_widget_get_window (gtk_widget_get_toplevel(pMenu)), &x, &y);
 
176
        
 
177
        double fRadius = CD_RADIUS, fLineWidth = myDialogsParam.iLineWidth;
 
178
        double fDockOffsetX = fRadius + fLineWidth/2;
 
179
        double fDockOffsetY = fLineWidth/2;
 
180
        double fFrameWidth, fFrameHeight;
 
181
        fFrameWidth = w - 2*fRadius - fLineWidth;
 
182
        fFrameHeight = h - fLineWidth;
 
183
        switch (iMarginPosition)
 
184
        {
 
185
                case 0:  // bottom
 
186
                        fFrameHeight -= ah;
 
187
                break;
 
188
                case 1:  // top
 
189
                        fFrameHeight -= ah;
 
190
                        fDockOffsetY += ah;
 
191
                break;
 
192
                case 2:  // right
 
193
                        fFrameWidth -= ah;
 
194
                break;
 
195
                case 3:  // left
 
196
                        fFrameWidth -= ah;
 
197
                        fDockOffsetX += ah;
 
198
                break;
 
199
                default:
 
200
                break;
 
201
        }
 
202
        
 
203
        double fTipHeight = ah + fRadius;  // we want the tip of the arrow to reach the border, not the middle of the stroke
 
204
        double dh = fTipHeight + fRadius;
 
205
        int iDeltaIconX = 0, iDeltaIconY = 0;
 
206
        double dh1, dh2;
 
207
        switch (iMarginPosition)
 
208
        {
 
209
                case 0:
 
210
                case 1:
 
211
                        dh = MIN (dh, .3 * w);
 
212
                        iDeltaIconX = iAimedX - (x + w/2);
 
213
                        if (fabs (iDeltaIconX) < 3)  // filter useless tiny delta (and rounding errors).
 
214
                                iDeltaIconX = 0;
 
215
                        if (iDeltaIconX != 0)  // on va limiter la courbature du petit cote.
 
216
                        {
 
217
                                double dhmin = dh * MAX (1. - fabs (iDeltaIconX) / (w/2), .5);
 
218
                                if (iDeltaIconX > 0)  // pointe decale vers la droite.
 
219
                                {
 
220
                                        dh1 = dhmin;
 
221
                                        dh2 = dh;
 
222
                                }
 
223
                                else
 
224
                                {
 
225
                                        dh1 = dh;
 
226
                                        dh2 = dhmin;
 
227
                                }
 
228
                        }
 
229
                        else
 
230
                        {
 
231
                                dh1 = dh2 = dh;
 
232
                        }
 
233
                break;
 
234
                case 2:
 
235
                case 3:
 
236
                        dh = MIN (dh, .3 * h);
 
237
                        iDeltaIconY = iAimedY - (y + h/2);
 
238
                        if (fabs (iDeltaIconY) < 3)  // filter useless tiny delta (and rounding errors).
 
239
                                iDeltaIconY = 0;
 
240
                        if (iDeltaIconY != 0)  // on va limiter la courbature du petit cote.
 
241
                        {
 
242
                                double dhmin = dh * MAX (1. - fabs (iDeltaIconY) / (h/2), .5);
 
243
                                if (iDeltaIconY > 0)  // pointe decale vers la droite.
 
244
                                {
 
245
                                        dh1 = dhmin;
 
246
                                        dh2 = dh;
 
247
                                }
 
248
                                else
 
249
                                {
 
250
                                        dh1 = dh;
 
251
                                        dh2 = dhmin;
 
252
                                }
 
253
                        }
 
254
                        else
 
255
                        {
 
256
                                dh1 = dh2 = dh;
 
257
                        }
 
258
                break;
 
259
                default:
 
260
                break;
 
261
        }
 
262
        
 
263
        if (iMarginPosition == 1)  // top arrow
 
264
        {
 
265
                cairo_move_to (pCairoContext, fLineWidth/2, fTipHeight);
 
266
                cairo_rel_curve_to (pCairoContext,
 
267
                        0, - dh2,
 
268
                        (w - fLineWidth)/2 + iDeltaIconX, - (fTipHeight - dh2),
 
269
                        (w - fLineWidth)/2 + iDeltaIconX, - fTipHeight);
 
270
                
 
271
                cairo_rel_curve_to (pCairoContext,
 
272
                        0, dh1,
 
273
                        (w - fLineWidth)/2 - iDeltaIconX, fTipHeight - dh1,
 
274
                        (w - fLineWidth)/2 - iDeltaIconX, fTipHeight);
 
275
        }
 
276
        else
 
277
        {
 
278
                cairo_move_to (pCairoContext, fDockOffsetX, fDockOffsetY);
 
279
                cairo_rel_line_to (pCairoContext, fFrameWidth, 0);
 
280
                //\_________________ Coin haut droit.
 
281
                if (iMarginPosition != 2)  // not right arrow
 
282
                        cairo_arc (pCairoContext,
 
283
                                fDockOffsetX + fFrameWidth, fDockOffsetY + fRadius,
 
284
                                fRadius,
 
285
                                -G_PI/2, 0.);
 
286
        }
 
287
        
 
288
        if (iMarginPosition == 2)  // right arrow
 
289
        {
 
290
                cairo_rel_curve_to (pCairoContext,
 
291
                        dh2, 0,
 
292
                        fTipHeight - dh2, fFrameHeight/2 + iDeltaIconY,
 
293
                        fTipHeight, fFrameHeight/2 + iDeltaIconY);
 
294
                
 
295
                cairo_rel_curve_to (pCairoContext,
 
296
                        - dh1, 0,
 
297
                        - (fTipHeight - dh1), fFrameHeight/2 - iDeltaIconY,
 
298
                        - fTipHeight, fFrameHeight/2 - iDeltaIconY);
 
299
        }
 
300
        else
 
301
        {
 
302
                cairo_rel_line_to (pCairoContext, 0, (fFrameHeight - fRadius * 2));
 
303
                //\_________________ Coin bas droit.
 
304
                if (iMarginPosition != 0)  // not bottom arrow
 
305
                        cairo_arc (pCairoContext,
 
306
                                fDockOffsetX + fFrameWidth, fDockOffsetY + fFrameHeight - fRadius,
 
307
                                fRadius,
 
308
                                0., G_PI/2);
 
309
        }
 
310
        
 
311
        if (iMarginPosition == 0)  // bottom arrow
 
312
        {
 
313
                cairo_rel_curve_to (pCairoContext,
 
314
                        0, dh1,
 
315
                        - (w - fLineWidth)/2 + iDeltaIconX, fTipHeight - dh1,
 
316
                        - (w - fLineWidth)/2 + iDeltaIconX, fTipHeight);
 
317
                
 
318
                cairo_rel_curve_to (pCairoContext,
 
319
                        0, - dh2,
 
320
                        - (w - fLineWidth)/2 - iDeltaIconX, - (fTipHeight - dh2),
 
321
                        - (w - fLineWidth)/2 - iDeltaIconX, - fTipHeight);
 
322
        }
 
323
        else
 
324
        {
 
325
                cairo_rel_line_to (pCairoContext, - fFrameWidth, 0);
 
326
                //\_________________ Coin bas gauche.
 
327
                if (iMarginPosition != 3)  // not left arrow
 
328
                        cairo_arc (pCairoContext,
 
329
                                fDockOffsetX, fDockOffsetY + fFrameHeight - fRadius,
 
330
                                fRadius,
 
331
                                G_PI/2, G_PI);
 
332
        }
 
333
        
 
334
        if (iMarginPosition == 3)  // left arrow
 
335
        {
 
336
                cairo_rel_curve_to (pCairoContext,
 
337
                        - dh2, 0,
 
338
                        - fTipHeight + dh2, - (fFrameHeight/2 + iDeltaIconY),
 
339
                        - fTipHeight, -(fFrameHeight/2 + iDeltaIconY));
 
340
                
 
341
                cairo_rel_curve_to (pCairoContext,
 
342
                        dh1, 0,
 
343
                        fTipHeight - dh1, -(fFrameHeight/2 - iDeltaIconY),
 
344
                        fTipHeight, - (fFrameHeight/2 - iDeltaIconY));
 
345
        }
 
346
        else
 
347
        {
 
348
                cairo_rel_line_to (pCairoContext, 0, (- fFrameHeight + fRadius * 2));
 
349
                //\_________________ Coin haut gauche.
 
350
                if (iMarginPosition != 1)  // not top arrow
 
351
                        cairo_arc (pCairoContext,
 
352
                                fDockOffsetX, fDockOffsetY + fRadius,
 
353
                                fRadius,
 
354
                                G_PI, -G_PI/2);
 
355
        }
 
356
        
 
357
        // draw the background
 
358
        if (myDialogsParam.bUseDefaultColors)
 
359
                gldi_style_colors_set_bg_color (pCairoContext);
 
360
        else
 
361
                cairo_set_source_rgba (pCairoContext, myDialogsParam.fBgColor[0], myDialogsParam.fBgColor[1], myDialogsParam.fBgColor[2], myDialogsParam.fBgColor[3]);
 
362
        cairo_save (pCairoContext);
 
363
        cairo_clip_preserve (pCairoContext);
 
364
        gldi_style_colors_paint_bg_color (pCairoContext, alloc.width);
 
365
        cairo_restore (pCairoContext);
 
366
        
 
367
        // draw outline
 
368
        if (fLineWidth != 0)  // draw the outline with same color as bg, but opaque
 
369
        {
 
370
                if (myDialogsParam.bUseDefaultColors)
 
371
                        gldi_style_colors_set_line_color (pCairoContext);
 
372
                else
 
373
                        cairo_set_source_rgba (pCairoContext, myDialogsParam.fLineColor[0], myDialogsParam.fLineColor[1], myDialogsParam.fLineColor[2], myDialogsParam.fLineColor[3]);
 
374
                cairo_stroke_preserve (pCairoContext);
 
375
        }
 
376
        
 
377
        cairo_clip (pCairoContext);  // clip
 
378
}
 
379
 
 
380
static void _setup_menu (GtkWidget *pMenu)
 
381
{
 
382
        GldiMenuParams *pParams = g_object_get_data (G_OBJECT(pMenu), "gldi-params");
 
383
        pParams->iRadius = CD_RADIUS;
 
384
        pParams->fAlign = CD_ALIGN;
 
385
        pParams->iArrowHeight = CD_ARROW_HEIGHT;
 
386
}
174
387
 
175
388
void cd_decorator_register_curly (void)
176
389
{
178
391
        pDecorator->set_size = cd_decorator_set_frame_size_curly;
179
392
        pDecorator->render = cd_decorator_draw_decorations_curly;
180
393
        pDecorator->render_opengl = NULL;
 
394
        pDecorator->setup_menu = _setup_menu;
 
395
        pDecorator->render_menu = _render_menu;
181
396
        pDecorator->cDisplayedName = D_ (MY_APPLET_DECORATOR_CURLY_NAME);
182
397
        cairo_dock_register_dialog_decorator (MY_APPLET_DECORATOR_CURLY_NAME, pDecorator);
183
398
}