~ubuntu-branches/ubuntu/natty/gnome-do/natty

« back to all changes in this revision

Viewing changes to Do.Interface.Linux.AnimationBase/src/Do.Interface/Do.Interface.AnimationBase/BezelDrawingArea.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2009-06-27 10:40:45 UTC
  • mfrom: (1.1.8 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090627104045-7st10y1cqr6dpz37
Tags: 0.8.2+dfsg-1
* New upstream release
  + No longer uses a plugin repository.  Fixes many plugin-
    related issues. (LP: #343096, LP: #330025, LP #345001)
  + No longer blocks on "About Do" (LP: #361679)
  + Reacts correctly when a Composite manager is enabled/
    disabled at runtime. (LP: #346347, LP: #390150)
  + Fixes for space reserved by Docky blocking drag and 
    drop operations. (LP: #354729, LP: #347052, LP: #382843)
  + Properly sets "Hidden" key on autostart files in response to 
    "Start on login" option.  (Closes: #526023) (LP: #369988)
* debian/patches/10_application_search_path:
  + Drop; included upstream
* debian/patches/10_sk_translation_update:
  + Import sk translation update from Debian BTS.
    (Closes: #531779)
* debian/patches/11_fix_autostart_when_directory_does_not_exist:
  + Patch from upstream.  Fixes the "Start on login" option when the 
    ~/.config/autostart directory does not exist. (LP: #393729)
* debian/control:
  + Update standards version to 3.8.2; no changes required.
  + Add libtool to Build-Depends; required for autoreconf.
  + Add Recommends: on new gnome-do-docklets package.
* debian/gnome-do.1
  + Fix spelling: GNOME-Do => GNOME Do.
  + Miscelaneous lintian fixes; NAME section, escaping minus signs with \-
* debian/copyright:
  + Update for new copyright holders.
  + Minor update to DEP-5 format

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// BeezelDrawingArea.cs
 
2
// 
 
3
// Copyright (C) 2008 GNOME-Do
 
4
//
 
5
// This program is free software: you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation, either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
//
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
//
 
18
 
 
19
using System;
 
20
using System.Collections.Generic;
 
21
 
 
22
using Cairo;
 
23
using Gdk;
 
24
using Gtk;
 
25
 
 
26
using Mono.Unix;
 
27
 
 
28
using Do.Interface;
 
29
using Do.Interface.CairoUtils;
 
30
using Do.Universe;
 
31
using Do.Platform;
 
32
 
 
33
namespace Do.Interface.AnimationBase
 
34
{
 
35
        public enum PointLocation {
 
36
                Window,
 
37
                Close,
 
38
                Preferences,
 
39
                Outside,
 
40
        }
 
41
        
 
42
        public enum HUDStyle {
 
43
                HUD,
 
44
                Classic,
 
45
        }
 
46
        
 
47
        public class BezelDrawingArea : Gtk.DrawingArea
 
48
        {
 
49
                enum DrawState {
 
50
                        Normal,
 
51
                        Text,
 
52
                        NoResult,
 
53
                        None,
 
54
                }
 
55
                
 
56
#region Static Area
 
57
                static IPreferences prefs = Services.Preferences.Get<BezelDrawingArea> ();
 
58
                public static event EventHandler ThemeChanged;
 
59
                
 
60
                public static bool Animated {
 
61
                        get {
 
62
                                return prefs.Get<bool> ("Animated", true);
 
63
                        }
 
64
                        set {
 
65
                                prefs.Set<bool> ("Animated", value);
 
66
                        }
 
67
                }
 
68
                
 
69
                public static string TitleRenderer {
 
70
                        get {
 
71
                                return prefs.Get<string> ("TitleRenderer", "default");
 
72
                        }
 
73
                        set {
 
74
                                prefs.Set<string> ("TitleRenderer", value);
 
75
                                OnThemeChanged ();
 
76
                        }
 
77
                }
 
78
                
 
79
                public static string PaneRenderer {
 
80
                        get {
 
81
                                return prefs.Get<string> ("PaneRenderer", "default");
 
82
                        }
 
83
                        set {
 
84
                                prefs.Set<string> ("PaneRenderer", value);
 
85
                                OnThemeChanged ();
 
86
                        }
 
87
                }
 
88
                
 
89
                public static string WindowRenderer {
 
90
                        get {
 
91
                                return prefs.Get<string> ("WindowRenderer", "default");
 
92
                        }
 
93
                        set {
 
94
                                prefs.Set<string> ("WindowRenderer", value);
 
95
                                OnThemeChanged ();
 
96
                        }
 
97
                }
 
98
                
 
99
                public static string BgColor {
 
100
                        get {
 
101
                                return prefs.Get<string> ("BackgroundColor", "default");
 
102
                        }
 
103
                        set {
 
104
                                prefs.Set<string> ("BackgroundColor", value);
 
105
                                OnThemeChanged ();
 
106
                        }
 
107
                }
 
108
                
 
109
                public static int RoundingRadius { 
 
110
                        get { 
 
111
                                return prefs.Get<int> ("WindowRadius", -1);
 
112
                        } 
 
113
                        set {
 
114
                                prefs.Set<int> ("WindowRadius", Math.Max (-1, value));
 
115
                                OnThemeChanged ();
 
116
                        }
 
117
                }
 
118
                
 
119
                public static bool DrawShadow {
 
120
                        get {
 
121
                                return prefs.Get<bool> ("Shadow", true);
 
122
                        }
 
123
                        set {
 
124
                                prefs.Set<bool> ("Shadow", value);
 
125
                                OnThemeChanged ();
 
126
                        }
 
127
                }
 
128
                
 
129
                public static void SetDefaultStyle ()
 
130
                {
 
131
                        DrawShadow = true;
 
132
                        prefs.Set<int> ("WindowRadius", -1);
 
133
                }
 
134
                
 
135
                public static void ResetBackgroundStyle ()
 
136
                {
 
137
                        prefs.Set<string> ("BackgroundColor", "default");
 
138
                        OnThemeChanged ();
 
139
                }
 
140
                
 
141
                private static void OnThemeChanged ()
 
142
                {
 
143
                        if (ThemeChanged != null)
 
144
                                ThemeChanged (new System.Object (), new EventArgs ());
 
145
                }
 
146
#endregion
 
147
                
 
148
                public const int TextHeight = 11;
 
149
                
 
150
                HUDStyle style;
 
151
                
 
152
                const int BoxLineWidth    = 1;
 
153
                const int BorderWidth     = 15;
 
154
                const int fade_ms         = 150;
 
155
                const int ShadowRadius    = 10;
 
156
                
 
157
                IBezelTitleBarRenderElement  titleBarRenderer;
 
158
                IBezelWindowRenderElement    backgroundRenderer;
 
159
                IBezelPaneRenderElement      paneOutlineRenderer;
 
160
                IBezelOverlayRenderElement   textModeOverlayRenderer;
 
161
                IBezelDefaults               bezelDefaults;
 
162
                
 
163
                IRenderTheme theme;
 
164
                
 
165
                IDoController controller;
 
166
                
 
167
                BezelColors colors;
 
168
                BezelGlassResults bezel_results;
 
169
                
 
170
                bool third_pane_visible, preview;
 
171
                BezelDrawingContext context, old_context;
 
172
                PixbufSurfaceCache surface_cache;
 
173
                Pane focus;
 
174
                DateTime delta_time;
 
175
                uint timer;
 
176
                
 
177
                Gdk.Rectangle drawing_area;
 
178
                Surface surface;
 
179
                
 
180
                double text_box_scale, window_fade = 1, window_scale=1;
 
181
                
 
182
                double[] icon_fade = new double [] {1, 1, 1};
 
183
                bool[] entry_mode = new bool[3];
 
184
                
 
185
                public Cairo.Color BackgroundColor {
 
186
                        get {
 
187
                                Gdk.Color color = new Gdk.Color ();
 
188
                                if (Gdk.Color.Parse ("#" + BgColor.Substring (0, 6), ref color)) {
 
189
                                        if (BgColor.Length == 8) {
 
190
                                                double alpha = Convert.ToInt32 (BgColor.Substring (6, 2), 16);
 
191
                                                alpha = alpha / 255;
 
192
                                                return color.ConvertToCairo (alpha);
 
193
                                        }
 
194
                                        return color.ConvertToCairo (backgroundRenderer.BackgroundColor.A);
 
195
                                }
 
196
                                return backgroundRenderer.BackgroundColor;
 
197
                        }
 
198
                }
 
199
                
 
200
                public int BoxWidth { 
 
201
                        get { return PaneOutlineRenderer.Width; } 
 
202
                }
 
203
                
 
204
                public int BoxHeight { 
 
205
                        get { return PaneOutlineRenderer.Height; } 
 
206
                }
 
207
                
 
208
                public Pane Focus {
 
209
                        get { return focus; }
 
210
                        set { 
 
211
                                if (focus == value)
 
212
                                        return;
 
213
                                focus = value;
 
214
                                AnimatedDraw ();
 
215
                        }
 
216
                }
 
217
                
 
218
                public BezelColors Colors {
 
219
                        get {
 
220
                                return colors;
 
221
                        }
 
222
                }
 
223
                
 
224
                public TextRenderer TextUtility { get; set; }
 
225
                
 
226
                public int IconSize {
 
227
                        get {
 
228
                                return paneOutlineRenderer.IconSize;
 
229
                        }
 
230
                }
 
231
                
 
232
                public int InternalHeight {
 
233
                        get {
 
234
                                if (BezelDefaults.RenderDescriptionText)
 
235
                                        return BoxHeight + 2 * WindowBorder + TextHeight + TitleBarHeight;
 
236
                                return BoxHeight + 2 * WindowBorder + TitleBarHeight;
 
237
                        }
 
238
                }
 
239
 
 
240
                public BezelGlassResults Results {
 
241
                        get {
 
242
                                if (bezel_results == null) 
 
243
                                        bezel_results = new BezelGlassResults (controller, Math.Min (TwoPaneWidth - 2 * WindowRadius, 360), style, colors);
 
244
                                return bezel_results;
 
245
                        }
 
246
                }
 
247
                
 
248
                public int TextModeOffset {
 
249
                        get { 
 
250
                                return Math.Max (TitleBarHeight, WindowRadius); 
 
251
                        }
 
252
                }
 
253
                
 
254
                public bool ThirdPaneVisible {
 
255
                        get { return third_pane_visible; }
 
256
                        set { 
 
257
                                third_pane_visible = value; 
 
258
                                if (third_pane_visible)
 
259
                                AnimatedDraw ();
 
260
                        }
 
261
                }
 
262
                
 
263
                public int ThreePaneWidth { 
 
264
                        get { 
 
265
                                return (2 * WindowBorder - BorderWidth) + (BoxWidth + BorderWidth) * 3; 
 
266
                        } 
 
267
                }
 
268
                
 
269
                public int TitleBarHeight { 
 
270
                        get { 
 
271
                                return TitleBarRenderer.Height; 
 
272
                        } 
 
273
                }
 
274
                
 
275
                public int TwoPaneWidth { 
 
276
                        get { 
 
277
                                return (2 * WindowBorder) - BorderWidth + ((BoxWidth + (BorderWidth)) * 2); 
 
278
                        } 
 
279
                }
 
280
                
 
281
                public string HighlightFormat { 
 
282
                        get { 
 
283
                                if (colors.Background.B == colors.Background.G && colors.Background.B == colors.Background.R)
 
284
                                        return BezelDefaults.HighlightFormat; 
 
285
                                else
 
286
                                        return "<span underline=\"single\"><b>{0}</b></span>";
 
287
                        } 
 
288
                }
 
289
                
 
290
                public int WindowBorder { 
 
291
                        get { 
 
292
                                return BezelDefaults.WindowBorder; 
 
293
                        } 
 
294
                }
 
295
                
 
296
                public int WindowHeight {
 
297
                        get {
 
298
                                return InternalHeight + 2 * ShadowRadius;
 
299
                        }
 
300
                }
 
301
                
 
302
                public int WindowRadius { 
 
303
                        get { 
 
304
                                if (RoundingRadius <= -1)
 
305
                                        return BezelDefaults.WindowRadius; 
 
306
                                return Math.Max (1, prefs.Get<int> ("WindowRadius", -1));
 
307
                        } 
 
308
                }
 
309
                
 
310
                public int WindowWidth { 
 
311
                        get { 
 
312
                                return (2 * WindowBorder - BorderWidth) + ((BoxWidth + BorderWidth) * 3) + 2 * ShadowRadius; 
 
313
                        } 
 
314
                }
 
315
                
 
316
                private bool AnimationNeeded {
 
317
                        get {
 
318
                                return  ExpandNeeded || 
 
319
                                            ShrinkNeeded || 
 
320
                                                TextScaleNeeded || 
 
321
                                                FadeNeeded || 
 
322
                                                WindowFadeNeeded;
 
323
                        }
 
324
                }
 
325
                
 
326
                private bool ExpandNeeded {
 
327
                        get {
 
328
                                bool shouldBeExpanded = ThirdPaneVisible || entry_mode [(int) Focus];
 
329
                                bool isNotExpanded = drawing_area.Width != ThreePaneWidth;
 
330
                                return shouldBeExpanded && isNotExpanded;
 
331
                        }
 
332
                }
 
333
                
 
334
                private bool ShrinkNeeded {
 
335
                        get {
 
336
                                bool shouldNotBeExpanded = !ThirdPaneVisible && !entry_mode [(int) focus];
 
337
                                return shouldNotBeExpanded  && (drawing_area.Width != TwoPaneWidth) && (Focus != Pane.Third);
 
338
                        }
 
339
                }
 
340
                
 
341
                private bool FadeNeeded {
 
342
                        get {
 
343
                                return icon_fade [0] != 1 || 
 
344
                                           icon_fade [1] != 1 || 
 
345
                                           icon_fade [2] != 1;
 
346
                        }
 
347
                }
 
348
                
 
349
                private bool TextScaleNeeded {
 
350
                        get {
 
351
                                bool textBoxNeedsExpand = entry_mode [(int) Focus] && text_box_scale != 1;
 
352
                                bool textBoxNeedsShrink = !entry_mode [(int) Focus] && text_box_scale != 0;
 
353
                                return textBoxNeedsExpand || textBoxNeedsShrink;
 
354
                        }
 
355
                }
 
356
                
 
357
                private bool WindowFadeNeeded {
 
358
                        get {
 
359
                                return window_fade != 1;
 
360
                        }
 
361
                }
 
362
                
 
363
                private BezelDrawingContext Context {
 
364
                        get {
 
365
                                if (context == null)
 
366
                                        context = new BezelDrawingContext ();
 
367
                                return context;
 
368
                        }
 
369
                }
 
370
                
 
371
                private BezelDrawingContext OldContext {
 
372
                        get {
 
373
                                if (old_context == null)
 
374
                                        old_context = new BezelDrawingContext ();
 
375
                                return old_context;
 
376
                        }
 
377
                }
 
378
                
 
379
                public IBezelTitleBarRenderElement TitleBarRenderer { 
 
380
                        get { return titleBarRenderer; } 
 
381
                }
 
382
 
 
383
                public IBezelWindowRenderElement BackgroundRenderer { 
 
384
                        get { return backgroundRenderer; } 
 
385
                }
 
386
 
 
387
                public IBezelPaneRenderElement PaneOutlineRenderer { 
 
388
                        get { return paneOutlineRenderer; } 
 
389
                }
 
390
 
 
391
                public IBezelOverlayRenderElement TextModeOverlayRenderer {     
 
392
                        get { return textModeOverlayRenderer; } 
 
393
                }
 
394
 
 
395
                public IBezelDefaults BezelDefaults { 
 
396
                        get { return bezelDefaults; }   
 
397
                }
 
398
                
 
399
                public event EventHandler GtkThemeChanged;
 
400
                
 
401
                public BezelDrawingArea (IDoController controller, IRenderTheme theme, bool preview) : base ()
 
402
                {
 
403
                        this.controller = controller;
 
404
                        TextUtility = new TextRenderer (this);
 
405
                        
 
406
                        DoubleBuffered = false;
 
407
                        prefs = Services.Preferences.Get<BezelDrawingArea> ();
 
408
                        this.preview = preview;
 
409
                        this.theme = theme;
 
410
                        
 
411
                        if (theme.Name == "Nouveau") //this is a temporary hack
 
412
                                style = HUDStyle.HUD;
 
413
                        else
 
414
                                style = HUDStyle.Classic; //gets us the classic results list
 
415
                        
 
416
                        ResetRenderStyle ();
 
417
                        SetDrawingArea ();
 
418
                        
 
419
                        BezelDrawingArea.ThemeChanged += OnThemeChanged;
 
420
                        Realized += delegate {
 
421
                                GdkWindow.SetBackPixmap (null, false);
 
422
                        };
 
423
                        
 
424
                        StyleSet += delegate {
 
425
                                if (IsRealized)
 
426
                                        GdkWindow.SetBackPixmap (null, false);
 
427
                        };
 
428
                }
 
429
                
 
430
                private void SetDrawingArea ()
 
431
                {
 
432
                        if (preview && TwoPaneWidth > 400) {
 
433
                                window_scale = 400.0 / TwoPaneWidth;
 
434
                        }
 
435
                        SetSizeRequest ((int) Math.Floor (WindowWidth * window_scale), (int) Math.Floor (WindowHeight * window_scale));
 
436
                        drawing_area  = new Gdk.Rectangle ((WindowWidth - TwoPaneWidth) / 2, ShadowRadius, TwoPaneWidth, InternalHeight);
 
437
                        if (preview)
 
438
                                drawing_area.X = ShadowRadius;
 
439
                }
 
440
                
 
441
                private void ResetRenderStyle ()
 
442
                {
 
443
                        BuildRenderers ();
 
444
                        
 
445
                        if (colors == null)
 
446
                                colors = new BezelColors (BackgroundColor);
 
447
                        else
 
448
                                colors.RebuildColors (BackgroundColor);
 
449
                        
 
450
                        SetDrawingArea ();
 
451
                }
 
452
                
 
453
                private void BuildRenderers ()
 
454
                {
 
455
                        bezelDefaults           = theme.GetDefaults (this);
 
456
                        titleBarRenderer        = theme.GetTitleBar (this);
 
457
                        textModeOverlayRenderer = theme.GetOverlay (this);
 
458
                        backgroundRenderer      = theme.GetWindow (this);
 
459
                        paneOutlineRenderer     = theme.GetPane (this);
 
460
                }
 
461
                
 
462
                public PixbufSurfaceCache SurfaceCache {
 
463
                        get {
 
464
                                if (surface_cache == null) {
 
465
                                        using (Context cr = CairoHelper.Create (GdkWindow))
 
466
                                                surface_cache = new PixbufSurfaceCache (50, IconSize, IconSize, cr.Target);
 
467
                                }
 
468
                                return surface_cache;
 
469
                        }
 
470
                }
 
471
 
 
472
                private void AnimatedDraw ()
 
473
                {
 
474
                        if (!IsDrawable || timer > 0)
 
475
                                return;
 
476
 
 
477
                        if (preview) {
 
478
                                Paint ();
 
479
                                return;
 
480
                        }
 
481
                        
 
482
                        delta_time = DateTime.Now;
 
483
                        timer = GLib.Timeout.Add (1000 / 65, OnDrawTimeoutElapsed);
 
484
                }
 
485
                
 
486
                private DrawState PaneDrawState (Pane pane)
 
487
                {
 
488
                        if (pane == Pane.Third && !ThirdPaneVisible)
 
489
                                return DrawState.None;
 
490
                        
 
491
                        if (Context.GetPaneTextMode (pane))
 
492
                                return DrawState.Text;
 
493
                        
 
494
                        if (Context.GetPaneObject (pane) != null)
 
495
                                return DrawState.Normal;
 
496
                        
 
497
                        if (!string.IsNullOrEmpty (Context.GetPaneQuery (pane))) {
 
498
                                return DrawState.NoResult;
 
499
                        }
 
500
                        
 
501
                        return DrawState.None;
 
502
                }
 
503
                
 
504
                public void BezelSetPaneObject (Pane pane, Do.Universe.Item obj)
 
505
                {
 
506
                        if (Context.GetPaneObject (pane) == obj && obj != null)
 
507
                                return;
 
508
                        
 
509
                        OldContext.SetPaneObject (pane, Context.GetPaneObject (pane));
 
510
                        Context.SetPaneObject (pane, obj);
 
511
                        
 
512
                        icon_fade [(int) pane] = 0;
 
513
                        Draw ();
 
514
                }
 
515
                
 
516
                public void BezelSetTextMode (Pane pane, bool textMode)
 
517
                {
 
518
                        if (Context.GetPaneTextMode (pane) == textMode)
 
519
                                return;
 
520
                        
 
521
                        OldContext.SetPaneTextMode (pane, Context.GetPaneTextMode (pane));
 
522
                        Context.SetPaneTextMode (pane, textMode);
 
523
                        
 
524
                        Draw ();
 
525
                }
 
526
                
 
527
                public void BezelSetEntryMode (Pane pane, bool entryMode)
 
528
                {
 
529
                        entry_mode [(int) pane] = entryMode;
 
530
                        Draw ();
 
531
                }
 
532
                
 
533
                public void BezelSetQuery (Pane pane, string query)
 
534
                {
 
535
                        if (Context.GetPaneQuery (pane) == query)
 
536
                                return;
 
537
                        
 
538
                        OldContext.SetPaneQuery (pane, Context.GetPaneQuery (pane));
 
539
                        Context.SetPaneQuery (pane, query);
 
540
                        Draw ();
 
541
                }
 
542
                
 
543
                public void Clear ()
 
544
                {
 
545
                        context = new BezelDrawingContext ();
 
546
                        old_context = new BezelDrawingContext ();
 
547
                        entry_mode = new bool [3];
 
548
                        Draw ();
 
549
                }
 
550
                
 
551
                void Draw ()
 
552
                {
 
553
                        AnimatedDraw ();
 
554
                }
 
555
                
 
556
                void Paint () 
 
557
                {
 
558
                        if (!IsDrawable)
 
559
                                return;
 
560
                        Cairo.Context cr2 = Gdk.CairoHelper.Create (GdkWindow);
 
561
                        
 
562
                        //Much kudos to Ian McIntosh
 
563
                        if (surface == null)
 
564
                                surface = cr2.Target.CreateSimilar (cr2.Target.Content, WindowWidth, WindowHeight);
 
565
                        
 
566
                        Context cr = new Context (surface);
 
567
                        
 
568
                        if (preview) {
 
569
                                Gdk.Color bgColor;
 
570
                                using (Gtk.Style rcstyle = Gtk.Rc.GetStyle (this)) {
 
571
                                        bgColor = rcstyle.Backgrounds[(int) StateType.Normal];
 
572
                                }
 
573
                                cr.Color = bgColor.ConvertToCairo (1);
 
574
                        } else {
 
575
                                cr.Color = new Cairo.Color (0, 0, 0, 0);
 
576
                        }                       
 
577
                        cr.Operator = Cairo.Operator.Source;
 
578
                        cr.Paint ();
 
579
                        cr.Operator = Cairo.Operator.Over;
 
580
                        
 
581
                        BackgroundRenderer.RenderItem (cr, drawing_area);
 
582
                        
 
583
                        RenderTitleBar (cr);
 
584
                        do {
 
585
                                if (text_box_scale > 0) {
 
586
                                        
 
587
                                        RenderTextModeOverlay (cr);
 
588
                                        if (text_box_scale == 1) {
 
589
                                                RenderTextModeText (cr);
 
590
                                                continue;
 
591
                                        }
 
592
                                }
 
593
                                
 
594
                                if (BezelDefaults.RenderDescriptionText)
 
595
                                        RenderDescriptionText (cr);
 
596
                                //--------------First Pane---------------
 
597
                                RenderPane (Pane.First, cr);
 
598
                                //------------Second Pane----------------
 
599
                                RenderPane (Pane.Second, cr);
 
600
                                //------------Third Pane-----------------
 
601
                                if (ThirdPaneVisible) {
 
602
                                        RenderPane (Pane.Third, cr);
 
603
                                }
 
604
 
 
605
                                if (text_box_scale > 0) {
 
606
                                        RenderTextModeOverlay (cr);
 
607
                                }
 
608
                                
 
609
                        } while (false);
 
610
                        
 
611
                        if (DrawShadow)
 
612
                                Util.Appearance.DrawShadow (cr, drawing_area.X, drawing_area.Y, drawing_area.Width, 
 
613
                                                            drawing_area.Height, WindowRadius, new Util.ShadowParameters (.5, ShadowRadius));
 
614
 
 
615
                        if (window_scale != 1) //we are likely in preview mode, though this can be set on the fly
 
616
                                cr2.Scale (window_scale, window_scale);
 
617
                        cr2.SetSourceSurface (surface, 0, 0);
 
618
                        cr2.Operator = Operator.Source;
 
619
                        cr2.Paint ();
 
620
 
 
621
                        (cr2.Target).Destroy ();
 
622
                        ((IDisposable)cr2.Target).Dispose ();
 
623
                        ((IDisposable)cr2).Dispose ();
 
624
                        
 
625
                        ((IDisposable)cr).Dispose ();
 
626
                }
 
627
                
 
628
                protected override void OnDestroyed ()
 
629
                {
 
630
                        base.OnDestroyed ();
 
631
                        BezelDrawingArea.ThemeChanged -= OnThemeChanged;
 
632
                        if (surface != null)
 
633
                                surface.Destroy ();
 
634
                        context = old_context = null;
 
635
                }
 
636
                
 
637
                protected bool OnDrawTimeoutElapsed ()
 
638
                {
 
639
                        double change = (Animated) ? DateTime.Now.Subtract (delta_time).TotalMilliseconds / fade_ms : 10;
 
640
                        
 
641
                        delta_time = DateTime.Now;
 
642
                        if (ExpandNeeded) {
 
643
                                drawing_area.Width += (int) ((ThreePaneWidth - TwoPaneWidth) * change);
 
644
                                drawing_area.Width = (drawing_area.Width > ThreePaneWidth) ? ThreePaneWidth : drawing_area.Width;
 
645
                                drawing_area.X = (WindowWidth - drawing_area.Width) / 2;
 
646
                        } else if (ShrinkNeeded) {
 
647
                                drawing_area.Width -= (int) ((ThreePaneWidth - TwoPaneWidth) * change);
 
648
                                drawing_area.Width = (drawing_area.Width < TwoPaneWidth) ? TwoPaneWidth : drawing_area.Width;
 
649
                                drawing_area.X = (WindowWidth - drawing_area.Width) / 2;
 
650
                        }
 
651
                        
 
652
                        if (TextScaleNeeded) {
 
653
                                if (entry_mode [(int) Focus]) {
 
654
                                        text_box_scale += change;
 
655
                                        text_box_scale = (text_box_scale > 1) ? 1 : text_box_scale;
 
656
                                } else {
 
657
                                        text_box_scale -= change;
 
658
                                        text_box_scale = (text_box_scale < 0) ? 0 : text_box_scale;
 
659
                                }
 
660
                        }
 
661
                        
 
662
                        if (FadeNeeded) {
 
663
                                if (text_box_scale == 1) {
 
664
                                        icon_fade [0] = icon_fade [1] = icon_fade [2] = 1;
 
665
                                }
 
666
                                icon_fade [0] += change;
 
667
                                icon_fade [1] += change;
 
668
                                icon_fade [2] += change;
 
669
                                
 
670
                                icon_fade [0] = (icon_fade [0] > 1) ? 1 : icon_fade [0];
 
671
                                icon_fade [1] = (icon_fade [1] > 1) ? 1 : icon_fade [1];
 
672
                                icon_fade [2] = (icon_fade [2] > 1) ? 1 : icon_fade [2];
 
673
                        }
 
674
                        
 
675
                        if (WindowFadeNeeded) {
 
676
                                window_fade += (change * .1) + (window_fade / 2);
 
677
                                window_fade = Math.Min (window_fade, 1);
 
678
                        }
 
679
                        
 
680
                        QueueDraw ();
 
681
                        
 
682
                        if (AnimationNeeded) {
 
683
                                return true;
 
684
                        } else {
 
685
                                timer = 0;
 
686
                                return false;
 
687
                        }
 
688
                }
 
689
                
 
690
                protected override bool OnExposeEvent (EventExpose evnt)
 
691
                {
 
692
                        bool ret = base.OnExposeEvent (evnt);
 
693
                        Paint ();
 
694
                        return ret;
 
695
                }
 
696
                
 
697
                protected override void OnStyleSet (Gtk.Style previous_style)
 
698
                {
 
699
                        if (GtkThemeChanged != null)
 
700
                                GtkThemeChanged (this, System.EventArgs.Empty);
 
701
                        Colors.RebuildColors (BackgroundColor);
 
702
                        base.OnStyleSet (previous_style);
 
703
                }
 
704
 
 
705
                private void OnThemeChanged (object o, System.EventArgs args)
 
706
                {
 
707
                        ResetRenderStyle ();
 
708
                        QueueDraw ();
 
709
                }
 
710
                
 
711
                public int PaneOffset (Pane pane) 
 
712
                {
 
713
                        return WindowBorder + ((int) pane * (BoxWidth + BorderWidth));
 
714
                }
 
715
                
 
716
                private void RenderPane (Pane pane, Context cr)
 
717
                {
 
718
                        if (pane == Pane.Third) {
 
719
                                cr.Rectangle (drawing_area.X, drawing_area.Y, drawing_area.Width, drawing_area.Height);
 
720
                                cr.Clip ();
 
721
                        }
 
722
                        RenderPaneOutline (pane, cr);
 
723
                        
 
724
                        switch (PaneDrawState (pane)) {
 
725
                        case DrawState.Normal:
 
726
                                RenderPixbuf (pane, cr);
 
727
                                RenderPaneText (pane, cr);
 
728
                                break;
 
729
                        case DrawState.NoResult:
 
730
                                RenderPixbuf (pane, cr, "gtk-question-dialog", 1);
 
731
                                RenderPaneText (pane, cr, string.Format (Catalog.GetString ("No results for: {0}"), Context.GetPaneQuery (pane)));
 
732
                                break;
 
733
                        case DrawState.Text:
 
734
                                if (text_box_scale < 1) {
 
735
                                        RenderPixbuf (pane, cr, "gnome-mime-text", .1);
 
736
                                        RenderPaneText (pane, cr);
 
737
                                }
 
738
                                break;
 
739
                        case DrawState.None:
 
740
                                if (pane == Pane.First) {
 
741
                                        RenderPixbuf (pane, cr, "search", 1);
 
742
                                        RenderPaneText (pane, cr, Catalog.GetString ("Type To Search"));
 
743
                                }
 
744
                                break;
 
745
                        }
 
746
                        if (pane == Pane.Third)
 
747
                                cr.ResetClip ();
 
748
                }
 
749
                
 
750
                private void RenderPaneOutline (Pane pane, Context cr)
 
751
                {
 
752
                        Gdk.Rectangle render_region = new Gdk.Rectangle () {
 
753
                                Width = BoxWidth,
 
754
                                Height = BoxHeight,
 
755
                                X = drawing_area.X + PaneOffset (pane),
 
756
                                Y = drawing_area.Y + WindowBorder + TitleBarHeight,
 
757
                        };
 
758
                        PaneOutlineRenderer.RenderItem (cr, render_region, (Focus == pane));
 
759
                }
 
760
                
 
761
                private void RenderPixbuf (Pane pane, Context cr)
 
762
                {
 
763
                        Do.Universe.Item obj = Context.GetPaneObject (pane);
 
764
                        RenderPixbuf (pane, cr, obj.Icon, 1);
 
765
                }
 
766
                
 
767
                private void RenderPixbuf (Pane pane, Context cr, string icon, double alpha)
 
768
                {
 
769
                        int offset = PaneOffset (pane);
 
770
                        if (!SurfaceCache.ContainsKey (icon)) {
 
771
                                BufferIcon (cr, icon);
 
772
                        }
 
773
                        
 
774
                        string sec_icon = "";
 
775
                        if (OldContext.GetPaneObject (pane) != null)
 
776
                                sec_icon = OldContext.GetPaneObject (pane).Icon;
 
777
                        
 
778
                        double calc_alpha = (sec_icon != icon) ? icon_fade[(int) pane] : 1;
 
779
                        int x;
 
780
                        int y;
 
781
                        if (PaneOutlineRenderer.StackIconText) {
 
782
                                x = drawing_area.X + offset + (BoxWidth / 2 - IconSize / 2);
 
783
                                y = drawing_area.Y + WindowBorder + TitleBarHeight + 3;
 
784
                        } else {
 
785
                                x = drawing_area.X + offset + 5;
 
786
                                y = drawing_area.Y + WindowBorder + TitleBarHeight + ((BoxHeight - IconSize) / 2);
 
787
                        }
 
788
                        cr.SetSource (SurfaceCache.GetSurface (icon), x, y);
 
789
                        cr.PaintWithAlpha (calc_alpha * alpha);
 
790
                        if (string.IsNullOrEmpty (sec_icon) || calc_alpha < 1) 
 
791
                                return;
 
792
                        
 
793
                        if (!SurfaceCache.ContainsKey (OldContext.GetPaneObject (pane).Icon)) {
 
794
                                BufferIcon (cr, OldContext.GetPaneObject (pane).Icon);
 
795
                        }
 
796
                        cr.SetSource (SurfaceCache.GetSurface (OldContext.GetPaneObject (pane).Icon), x, y);
 
797
                        cr.PaintWithAlpha (alpha * (1 - calc_alpha));
 
798
                }
 
799
                
 
800
                private void BufferIcon (Context cr, string icon)
 
801
                {
 
802
                        SurfaceCache.AddPixbufSurface (icon, icon);
 
803
                }
 
804
                
 
805
                void RenderDescriptionText (Context cr)
 
806
                {
 
807
                        if (Context.GetPaneObject (Focus) == null)
 
808
                                return;
 
809
                        string text = GLib.Markup.EscapeText (Context.GetPaneObject (Focus).Description);
 
810
                        int x = drawing_area.X + 10;
 
811
                        int y = drawing_area.Y + InternalHeight - WindowBorder - 4;
 
812
                        TextUtility.RenderLayoutText (cr, text, x, y, drawing_area.Width - 20, TextHeight);
 
813
                }
 
814
                
 
815
                void RenderPaneText (Pane pane, Context cr)
 
816
                {
 
817
                        if (Context.GetPaneObject (pane) != null)
 
818
                                RenderPaneText (pane, cr, GLib.Markup.EscapeText (Context.GetPaneObject (pane).Name));
 
819
                }
 
820
                
 
821
                void RenderPaneText (Pane pane, Context cr, string text)
 
822
                {
 
823
                        if (text.Length == 0) return;
 
824
                        
 
825
                        if (Context.GetPaneTextMode (pane)) {
 
826
                                Pango.Color color = new Pango.Color ();
 
827
                                color.Blue = color.Green = color.Red = ushort.MaxValue;
 
828
                                int y = drawing_area.Y + WindowBorder + TitleBarHeight + 6;
 
829
                                int x = drawing_area.X + PaneOffset (pane) + 5;
 
830
                                
 
831
                                TextUtility.RenderLayoutText (cr, text, x, y, BoxWidth - 10, TextHeight, color, 
 
832
                                                              Pango.Alignment.Left, Pango.EllipsizeMode.None);
 
833
                        } else {
 
834
                                string query = Context.GetPaneQuery (pane); 
 
835
                                if (!string.IsNullOrEmpty (query)) {
 
836
                                        text = Util.FormatCommonSubstrings (text, query, HighlightFormat);
 
837
                                }
 
838
                                
 
839
                                if (PaneOutlineRenderer.StackIconText) {
 
840
                                        int y = drawing_area.Y + WindowBorder + TitleBarHeight + BoxHeight - TextHeight - 9;
 
841
                                        int x = drawing_area.X + PaneOffset (pane) + 5;
 
842
                                        TextUtility.RenderLayoutText (cr, text, x, y, BoxWidth - 10, TextHeight);
 
843
                                } else {
 
844
                                        int y = drawing_area.Y + WindowBorder + TitleBarHeight + (int)(BoxHeight/2);
 
845
                                        int x = drawing_area.X + PaneOffset (pane) + IconSize + 10;
 
846
                                        TextUtility.RenderLayoutText (cr, text, x, y, BoxWidth - IconSize - 20, TextHeight);
 
847
                                }
 
848
                        }
 
849
                }
 
850
                
 
851
                void RenderTextModeText (Context cr)
 
852
                {
 
853
                        Pango.Color color = new Pango.Color ();
 
854
                        color.Blue = color.Red = color.Green = (ushort) (ushort.MaxValue * text_box_scale);
 
855
                        Gdk.Rectangle cursor = TextUtility.RenderLayoutText (cr, GLib.Markup.EscapeText (Context.GetPaneQuery (Focus)), 
 
856
                                                                                drawing_area.X + 10, drawing_area.Y + TextModeOffset + 5, 
 
857
                                                                                drawing_area.Width - 20, 18, color, 
 
858
                                                                                Pango.Alignment.Left, Pango.EllipsizeMode.None);
 
859
                        if (cursor.X == cursor.Y && cursor.X == 0) return;
 
860
                        
 
861
                        cr.Rectangle (cursor.X, cursor.Y, 2, cursor.Height);
 
862
                        cr.Color = new Cairo.Color (.4, .5, 1, .85);
 
863
                        cr.Fill ();
 
864
                }
 
865
                
 
866
                void RenderTextModeOverlay (Context cr) 
 
867
                {
 
868
                        TextModeOverlayRenderer.RenderItem (cr, drawing_area, text_box_scale);
 
869
                }
 
870
                
 
871
                void RenderTitleBar (Context cr)
 
872
                {
 
873
                        TitleBarRenderer.RenderItem (cr, drawing_area);
 
874
                }
 
875
                
 
876
                public PointLocation GetPointLocation (Gdk.Point point)
 
877
                {
 
878
                        if (BackgroundRenderer.GetPointLocation (drawing_area, point) == PointLocation.Outside)
 
879
                                return PointLocation.Outside;
 
880
                        return TitleBarRenderer.GetPointLocation (drawing_area, point);
 
881
                }
 
882
        }
 
883
}