~ubuntu-branches/ubuntu/trusty/cairo-dock-plug-ins/trusty-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2014-04-07 00:48:03 UTC
  • mfrom: (48.1.3 cairo-dock-plug-ins)
  • Revision ID: package-import@ubuntu.com-20140407004803-5s5leqg9iplbngje
Tags: 3.3.99.beta1.2.really.3.3.2-0ubuntu1
* Revert back to the 3.3.2 version: (LP: #1302246)
  Unfortunately, due to the lack of time, we have to revert back to the
  latest stable version. Sorry for that but feel free to help us ;-)
* debian/patches: cherry-pick patches from upstream BZR repo, all 'bug-fix'
  and changes that were already in the 3.3.99.beta1 version except all
  changes linked to the new style, the menu and the configuration.
  - bzr3008_GMenu_new_apps_in_the_list.patch: GMenu: New Apps: if there are
    new apps when the 'new apps' dialogue is opened, add these new apps in
    the list
  - bzr3010_GMenu_option_hide_new_apps_dialogue.patch: GMenu: Config: Added
    the possibility to not display notification to quickly launch new apps
  - bzr3021_Terminal_launch_default_terminal_middle_click.patch: Terminal:
    middle click: launch the default terminal
  - bzr3031-3032_GMenu_remove_empty_submenus.patch: GMenu: do not add empty
    submenus when creating them and remove empty submenus
  - bzr3035_DND2Share_History_was_empty.patch: DnD2Share: history menu was
    empty
  - bzr3036-3040_Shortcuts_removed_disk_usage_on_bookmarks_and_support_
    x-nautilus_URI.patch: Shortcuts: correctly removed an old bookmark ;
    added support for x-nautilus-(...) URI ; avoid duplicated code +
    bookmarks doesn't have a disk usage ; translated a few sentences from
    French to English
  - bzr3043_Fixed_typo_with_some_sentences.patch: Fixed typo with some
    sentences which were not correctly translated
  - bzr3045-3046_GVFS_support_x-nautilus-desktop_and_fixed_typos_and_memory_
    leaks.patch: gvfs: fixed typo and tiny memory leak ; GTK3: 'x-nautilus-
    desktop' is just an URI where the root is the path to the desktop
  - bzr3047-3048_Status-Notifier_Added_support_of_middle_click_and_scroll:
    Status-Notifier: IAS (ubuntu): added the support of the middle click ;
    Scroll signals were not catched
  - bzr3051_Logout_Added_support_of_Cinnamon.patch: logout: added support of
    Cinnamon
  - bzr3057_GMenu_new_apps_show_dialog_after_installation.patch: GMenu: new
    apps: show the dialog only after the end of the installation
  - bzr3065_Impulse_do_not_redraw_icon_when_not_needed.patch: Impulse: stop
    animations: do not redraw the icon if it's not needed (e.g. when
    disabling the applet)
  - bzr3067_AlsaMixer_support_cinnamon_settings.patch: AlsaMixer: added the
    support of cinnamon-settings
  - bzr3068_Clock_fixed_a_crash_when_configuring_when_not_enabled.patch:
    Clock: fixed a crash when configuring the applet if it's not activated
  - bzr3069_Indicator_Generic_no_need_to_hide_the_icon_before_removing_it:
    Indicator Generic: stop: no need to hide the icon before removing it
* debian/control: bumped Core versions

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)
30
27
 
31
28
void cd_decorator_set_frame_size_curly (CairoDialog *pDialog)
32
29
{
33
 
        int iMargin = .5 * myDialogsParam.iLineWidth + (1. - sqrt (2) / 2) * CD_RADIUS;
 
30
        int iMargin = .5 * myConfig.iCurlyLineWidth + (1. - sqrt (2) / 2) * myConfig.iCurlyRadius;
34
31
        pDialog->iRightMargin = iMargin;
35
32
        pDialog->iLeftMargin = iMargin;
36
33
        pDialog->iTopMargin = iMargin;
37
 
        pDialog->iBottomMargin = iMargin;
38
 
        pDialog->iMinBottomGap = CD_ARROW_HEIGHT + CD_RADIUS;
 
34
        pDialog->iBottomMargin = 2*iMargin;
 
35
        pDialog->iMinBottomGap = MAX (20, 2*myConfig.iCurlyRadius);
39
36
        pDialog->iMinFrameWidth = 10;  // au pif.
40
37
        pDialog->fAlign = .5;
41
38
        pDialog->container.fRatio = 0.;
45
42
 
46
43
void cd_decorator_draw_decorations_curly (cairo_t *pCairoContext, CairoDialog *pDialog)
47
44
{
48
 
        double fLineWidth = myDialogsParam.iLineWidth;
49
 
        double fRadius = CD_RADIUS;
 
45
        double fLineWidth = myConfig.iCurlyLineWidth;
 
46
        double fRadius = myConfig.iCurlyRadius;
50
47
        // double fBottomRadius = 2 * fRadius;
51
 
        double fTipHeight = pDialog->iMinBottomGap + fLineWidth/2;
52
 
        double dh = MIN (fTipHeight + fRadius, .3 * pDialog->container.iWidth);
 
48
        double fTipHeight = pDialog->iMinBottomGap + 0*pDialog->iBottomMargin + fLineWidth/2;
 
49
        double dh = MIN (MAX (1, myConfig.fCurlyCurvature * fTipHeight), .4 * pDialog->container.iWidth);
53
50
        
54
51
        double fOffsetX = fRadius + fLineWidth / 2;
55
52
        double fOffsetY = (pDialog->container.bDirectionUp ? fLineWidth / 2 : pDialog->container.iHeight - fLineWidth / 2);
88
85
        cairo_set_tolerance (pCairoContext, 0.33);
89
86
        
90
87
        // Ligne du haut (Haut gauche -> Haut Droite)
91
 
        cairo_rel_line_to (pCairoContext,
92
 
                2*fDemiWidth,
93
 
                0.);
 
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);
94
97
        
95
98
        // Coin haut droit.
96
99
        cairo_rel_curve_to (pCairoContext,
99
102
                fRadius, sens * fRadius);
100
103
        
101
104
        // Ligne droite. (Haut droit -> Bas droit)
102
 
        double fHeight = pDialog->iBubbleHeight + pDialog->iTopMargin + pDialog->iBottomMargin - (fRadius + fLineWidth/2);
103
 
        cairo_rel_line_to (pCairoContext,
104
 
                0,
105
 
                sens * fHeight);
 
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
        }
106
124
        
107
125
        fDemiWidth = .5 * pDialog->container.iWidth - fLineWidth/2;
108
126
        // Coin bas droit et pointe.
118
136
                - fDemiWidth - iDeltaIconX, - sens * fTipHeight);
119
137
        
120
138
        // On remonte par la gauche.
121
 
        cairo_rel_line_to (pCairoContext,
122
 
                0,
123
 
                - sens * fHeight);
 
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
        }
124
156
        // Coin haut gauche.
125
157
        cairo_rel_curve_to (pCairoContext,
126
158
                0, 0,
130
162
                cairo_close_path (pCairoContext);
131
163
        
132
164
        // On remplit le fond.
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);
 
165
        cairo_set_source_rgba (pCairoContext, myDialogsParam.fDialogColor[0], myDialogsParam.fDialogColor[1], myDialogsParam.fDialogColor[2], myDialogsParam.fDialogColor[3]);
 
166
        cairo_fill_preserve (pCairoContext);
142
167
        
143
168
        // On trace le contour.
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
 
}
 
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
 
387
174
 
388
175
void cd_decorator_register_curly (void)
389
176
{
391
178
        pDecorator->set_size = cd_decorator_set_frame_size_curly;
392
179
        pDecorator->render = cd_decorator_draw_decorations_curly;
393
180
        pDecorator->render_opengl = NULL;
394
 
        pDecorator->setup_menu = _setup_menu;
395
 
        pDecorator->render_menu = _render_menu;
396
181
        pDecorator->cDisplayedName = D_ (MY_APPLET_DECORATOR_CURLY_NAME);
397
182
        cairo_dock_register_dialog_decorator (MY_APPLET_DECORATOR_CURLY_NAME, pDecorator);
398
183
}