~lasse-valentini/do-plugins/Enlarger

« back to all changes in this revision

Viewing changes to src/EnlargerAction.cs

  • Committer: Lasse Valentini Jensen
  • Date: 2009-07-22 21:20:43 UTC
  • Revision ID: lasse@fraekkert-20090722212043-5dshjxeh5hlz9kz3
First C# and gtk app ever, so i might have made some serious mistakes.
This plugin is to show some text by the users choice, and make it very large. It's inspired heavily
by a similar feature in Mac OsX and quicksilver.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Collections.Generic;
 
4
using System.Linq;
 
5
 
 
6
using Mono.Addins;
 
7
 
 
8
using Do.Universe;
 
9
using Do.Universe.Common;
 
10
 
 
11
namespace Enlarger
 
12
{
 
13
        public class EnlargerAction : Act
 
14
        {
 
15
                Gtk.Window textWindow;
 
16
                
 
17
                public override string Name { get { return "Enlarge!";} }
 
18
                public override string Description { get { return "Enlarge your Text!";} }
 
19
                public override string Icon { get { return "display-capplet"; } }
 
20
                
 
21
                public override IEnumerable<Type> SupportedItemTypes {
 
22
                        get {
 
23
                                yield return typeof (ITextItem);
 
24
                        }
 
25
                }
 
26
                
 
27
                public override IEnumerable<Type> SupportedModifierItemTypes {
 
28
                        get {
 
29
                                yield return typeof (ITextItem);
 
30
                        }
 
31
                }
 
32
                
 
33
                public override bool SupportsModifierItemForItems (IEnumerable<Item> items, Item modItem)
 
34
                {
 
35
                        return modItem is ITextItem;
 
36
                }
 
37
 
 
38
                public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems)
 
39
                {
 
40
                        string word, fullString;
 
41
                        fullString = "";
 
42
                        foreach (Item item in items) {
 
43
                                if (item is ITextItem) {
 
44
                                        word = (item as ITextItem).Text;
 
45
                                } else {
 
46
                                        continue;
 
47
                                }
 
48
                                fullString = string.Format("{0} {1}", fullString, word);
 
49
                        }
 
50
                        
 
51
                        Gdk.Color black = new Gdk.Color(0,0,0);
 
52
                        
 
53
                        System.Console.WriteLine("inden vinduet");
 
54
                        textWindow = new Gtk.Window("Enlarged Text window");
 
55
                        int width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
 
56
                        int height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height-200;
 
57
                        textWindow.SetDefaultSize(width,height);
 
58
                        textWindow.Resize(width,height);
 
59
                        textWindow.BorderWidth = 0;
 
60
                        textWindow.Decorated = false;
 
61
                        textWindow.Resizable = false;
 
62
                        textWindow.Opacity = 0.8;
 
63
                        textWindow.SetPosition(Gtk.WindowPosition.CenterAlways);
 
64
                        textWindow.ModifyBg(Gtk.StateType.Normal, black);
 
65
                        textWindow.TypeHint = Gdk.WindowTypeHint.Splashscreen;
 
66
                        
 
67
                
 
68
                        System.Console.WriteLine("Window config done");
 
69
                        
 
70
                        Gtk.Label label = new Gtk.Label("<span size=\"131072\" color=\"#EFEFEF\">"+fullString+"</span>");
 
71
                        label.UseMarkup = true;
 
72
                        label.Justify = Gtk.Justification.Center;
 
73
                        label.LineWrap = true;
 
74
                        label.LineWrapMode  = Pango.WrapMode.WordChar;
 
75
                        
 
76
                        Gtk.Button button = new Gtk.Button (label);
 
77
                        
 
78
                        
 
79
                        button.Relief = Gtk.ReliefStyle.None;
 
80
                        button.ModifyText(Gtk.StateType.Normal,new Gdk.Color(239,239,239));
 
81
                        button.ModifyBg(Gtk.StateType.Normal,black);
 
82
                        button.ModifyBg(Gtk.StateType.Prelight, black);
 
83
                        button.ModifyBg(Gtk.StateType.Active, black);
 
84
                        
 
85
                        button.Hide();
 
86
                        button.Released += HandleReleased;
 
87
                        button.Clicked += HandleReleased;
 
88
                        button.KeyReleaseEvent += HandleKeyReleaseEvent;
 
89
                        
 
90
                        System.Console.WriteLine("Button config done");
 
91
                        
 
92
                        textWindow.Add (button);
 
93
                        label.SetSizeRequest(width,-1);
 
94
                        textWindow.ShowAll ();
 
95
                        
 
96
                        System.Console.WriteLine("efter vinduet");
 
97
                        
 
98
                        return null;
 
99
                }
 
100
 
 
101
                void HandleReleased(object sender, EventArgs e)
 
102
                {
 
103
                        textWindow.Destroy();
 
104
                }
 
105
 
 
106
                void HandleKeyReleaseEvent(object o, Gtk.KeyReleaseEventArgs args)
 
107
                {
 
108
                        textWindow.Destroy();
 
109
                }
 
110
                
 
111
        }
 
112
}