~seriy-pr/gwibber/vkontakte-ru-plugin

« back to all changes in this revision

Viewing changes to client/stream-entry.vala

  • Committer: Sergey Prokhorov
  • Date: 2011-10-02 17:13:01 UTC
  • mfrom: (932.1.248 trunk)
  • Revision ID: root@seriyps.ru-20111002171301-tkxgikc7s6wvkoll
Merged with head

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by Neil Jagdish Patel <njpatel@gmail.com>
 
17
 */
 
18
 
 
19
public class StreamEntry : Gtk.Alignment
 
20
{
 
21
  private Gtk.VBox _vbox;
 
22
  private Gtk.Alignment _align;
 
23
  public GwibberGtk.InputTextView text_view;
 
24
  private Gtk.Label _spacing;
 
25
  public Gtk.Image private;
 
26
 
 
27
  private Gwibber.Service _service;
 
28
 
 
29
  private uint _anim_id = 0;
 
30
  private float _anim_offset = 0.0f;
 
31
  private int64 _anim_start = 0;
 
32
 
 
33
  public GwibberGtk.AccountTargetBar target_bar;
 
34
 
 
35
  private bool _showing = false;
 
36
  public bool showing {
 
37
    get {
 
38
      return _showing;
 
39
    }
 
40
    set {
 
41
      _showing = value;
 
42
      if (_showing)
 
43
        show ();
 
44
      else
 
45
      {
 
46
        private.hide ();
 
47
        target_bar.selected = null;
 
48
        text_view.hide ();
 
49
        _spacing.show ();
 
50
      }
 
51
    }
 
52
  }
 
53
 
 
54
  public StreamEntry ()
 
55
  {
 
56
    Object ();
 
57
  }
 
58
 
 
59
  construct
 
60
  {
 
61
    set_reallocate_redraws (true);
 
62
 
 
63
    _vbox = new Gtk.VBox (false, 0);
 
64
    add (_vbox);
 
65
 
 
66
    _align = new Gtk.Alignment (0.0f, 0.0f, 1.0f, 1.0f);
 
67
    _align.set_padding (18, 18, 18, 18);
 
68
    _vbox.pack_start (_align, false, false, 0);
 
69
 
 
70
    var box = new Gtk.VBox (false, 4);
 
71
    _align.add (box);
 
72
    _service = new Gwibber.Service ();
 
73
 
 
74
    var group = new Gtk.SizeGroup (Gtk.SizeGroupMode.VERTICAL);
 
75
 
 
76
    _spacing = new Gtk.Label (" ");
 
77
    box.pack_start (_spacing, false, true, 0);
 
78
    _spacing.set_no_show_all (true);
 
79
    _spacing.show ();
 
80
    group.add_widget (_spacing);
 
81
    
 
82
    text_view = new GwibberGtk.InputTextView (_service);
 
83
    text_view.set_wrap_mode (Gtk.WrapMode.WORD_CHAR);
 
84
    text_view.set_border_window_size (Gtk.TextWindowType.LEFT, 0);
 
85
    text_view.set_border_window_size (Gtk.TextWindowType.RIGHT, 0);
 
86
    text_view.set_border_window_size (Gtk.TextWindowType.TOP, 0);
 
87
    text_view.set_border_window_size (Gtk.TextWindowType.BOTTOM, 0);
 
88
    text_view.set_no_show_all (true);
 
89
    group.add_widget (text_view);
 
90
    box.pack_start (text_view, false, true, 0);
 
91
    text_view.key_press_event.connect ((t, e)=>
 
92
    {
 
93
      if (e.keyval == 65307) // Escape
 
94
      {
 
95
        showing = false;
 
96
        return true;
 
97
      }
 
98
      return false;
 
99
    });
 
100
 
 
101
    Gdk.RGBA color;
 
102
    color.red = 34/255.0f;
 
103
    color.green = 34/255.0f;
 
104
    color.blue = 34/255.0f;
 
105
    color.alpha = 1.0f;
 
106
    text_view.override_background_color (Gtk.StateFlags.NORMAL, color);
 
107
 
 
108
    color.red = 1.0f;
 
109
    color.green = 1.0f;
 
110
    color.blue = 1.0f;
 
111
    text_view.override_color (Gtk.StateFlags.NORMAL, color);
 
112
    text_view.fg_color = { 0, 65535, 65535, 65535 };
 
113
 
 
114
    color.alpha =0.5f;
 
115
    text_view.override_background_color (Gtk.StateFlags.SELECTED, color);
 
116
 
 
117
    color.red = 0.0f;
 
118
    color.green = 0.0f;
 
119
    color.blue = 0.0f;
 
120
    color.alpha = 1.0f;
 
121
    text_view.override_color (Gtk.StateFlags.SELECTED, color);
 
122
    
 
123
    var hbox = new Gtk.HBox (false, 12);
 
124
    box.pack_start (hbox, false, false, 0);
 
125
 
 
126
    private = new Gtk.Image.from_icon_name ("status_lock", Gtk.IconSize.MENU);
 
127
    private.set_no_show_all (true);
 
128
 
 
129
    hbox.pack_end (private, false, false, 0);
 
130
 
 
131
    target_bar = new GwibberGtk.AccountTargetBar ();
 
132
    hbox.pack_start (target_bar, true, true, 0);
 
133
    color.red = 1.0f;
 
134
    color.green = 1.0f;
 
135
    color.blue = 1.0f;
 
136
    color.alpha = 0.5f;
 
137
    target_bar.override_color (Gtk.StateFlags.NORMAL, color);
 
138
    target_bar.count.override_color (Gtk.StateFlags.NORMAL, color);
 
139
    
 
140
    target_bar.send.clicked.connect (()=>
 
141
    {
 
142
      text_view.submit ();
 
143
    });
 
144
 
 
145
    text_view.submit.connect (() =>
 
146
    {
 
147
      showing = false;
 
148
    });
 
149
 
 
150
    _align.size_allocate.connect_after (()=> { queue_draw (); });
 
151
    text_view.size_allocate.connect_after (()=> { queue_draw (); });
 
152
    box.size_allocate.connect_after (()=> { queue_draw (); });
 
153
 
 
154
    text_view.get_buffer ().changed.connect (() => 
 
155
    {
 
156
      target_bar.set_counter(text_view.get_buffer ().get_char_count ());
 
157
    });
 
158
 
 
159
    var eb = new Gtk.EventBox ();
 
160
    eb.set_visible_window (false);
 
161
    eb.set_above_child (false);
 
162
    _vbox.pack_end (eb, true, true, 0);
 
163
    eb.button_press_event.connect (()=> { showing = false; });
 
164
    
 
165
    notify["showing"].connect (()=>
 
166
    {
 
167
      if (_anim_id != 0)
 
168
        Source.remove (_anim_id);
 
169
 
 
170
      _anim_start = G.get_monotonic_time ();
 
171
 
 
172
        _anim_id = Timeout.add (15, ()=>
 
173
        {
 
174
          float LENGTH = 120000.0f;
 
175
          int64 diff = G.get_monotonic_time () - _anim_start;
 
176
          float progress = diff/LENGTH;
 
177
 
 
178
          queue_draw ();
 
179
          
 
180
          if (_showing)
 
181
          {
 
182
            _anim_offset = (_anim_offset + (1.0f-_anim_offset) * progress);
 
183
          }
 
184
          else
 
185
          {
 
186
            _anim_offset = _anim_offset - (_anim_offset * progress);
 
187
          }
 
188
 
 
189
          if (diff > LENGTH)
 
190
          {
 
191
            _anim_id = 0;
 
192
            _anim_offset = _showing ? 1.0f : 0.0f;
 
193
            text_view.visible = _showing;
 
194
            _spacing.visible = !_showing;
 
195
            set_visible (_showing);
 
196
            return false;
 
197
          }
 
198
 
 
199
          return true;
 
200
        });
 
201
    });
 
202
  }
 
203
 
 
204
  public override bool draw (Cairo.Context cr)
 
205
  {
 
206
    cr.push_group ();
 
207
 
 
208
    cr.save ();
 
209
 
 
210
    Gtk.Allocation a;
 
211
    _align.get_allocation (out a);
 
212
 
 
213
    cr.translate (0, (-1 * a.height) + (a.height * _anim_offset));
 
214
 
 
215
    a.height -= 12;
 
216
 
 
217
    var r = 4.0f; //radius
 
218
    cr.rectangle (a.x, a.y, a.width, a.height);
 
219
 
 
220
    var pat = new Cairo.Pattern.linear (0, 0, 0, _align.get_allocated_height ());
 
221
    pat.add_color_stop_rgba (0, 69/255.0, 69/255.0, 69/255.0, 0.85);
 
222
    pat.add_color_stop_rgba (1.0, 20/255.0, 20/255.0, 20/255.0, 0.85);
 
223
    cr.set_source (pat);
 
224
    cr.fill ();
 
225
 
 
226
    cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.3f);
 
227
    cr.rectangle (a.x, a.y, a.width, 1);
 
228
    cr.fill ();
 
229
 
 
230
    cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.2f);
 
231
    cr.rectangle (a.x, a.y + 1, a.width, 1);
 
232
    cr.fill ();
 
233
 
 
234
    cr.set_source_rgba (1.0f, 1.0f, 1.0f, 0.2f);
 
235
    cr.rectangle (a.x, a.y + a.height-2, a.width, 1);
 
236
    cr.fill ();
 
237
 
 
238
    cr.set_source_rgba (0.0f, 0.0f, 0.0f, 0.3f);
 
239
    cr.rectangle (a.x, a.y + a.height-1, a.width, 1);
 
240
    cr.fill ();
 
241
 
 
242
    // Shadow (we'll make it nicer later)
 
243
    pat = new Cairo.Pattern.linear (a.x, a.y + a.height, a.x, a.y + a.height + 12);
 
244
    pat.add_color_stop_rgba (0.0f, 0.0f, 0.0f, 0.0f, 0.4f);
 
245
    pat.add_color_stop_rgba (1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
 
246
    cr.rectangle (a.x, a.y + a.height, a.width, 12);
 
247
    cr.set_source (pat);
 
248
    cr.fill ();
 
249
 
 
250
    // Text View
 
251
    if (text_view.visible)
 
252
      text_view.get_allocation (out a);
 
253
    else
 
254
      _spacing.get_allocation (out a);
 
255
 
 
256
    pat = new Cairo.Pattern.linear (a.x, a.y, a.x, a.y + a.height);
 
257
    pat.add_color_stop_rgba (0.99, 24/255.0f, 24/255.0f, 24/255.0f, 1.0);
 
258
    pat.add_color_stop_rgba (1.0, 90/255.0f, 90/255.0f, 90/255.0f, 0.9);
 
259
    cr.set_source (pat);
 
260
 
 
261
    cr.rectangle (a.x - 1,
 
262
                  a.y - 1,
 
263
                  a.width + 2,
 
264
                  a.height + 2);
 
265
 
 
266
    cr.fill ();
 
267
 
 
268
    cr.move_to (a.x -1, a.y-1);
 
269
    cr.line_to (a.x -1 + a.width + 2, a.y-1);
 
270
    cr.set_source_rgba (10/255.0f, 10/255.0f, 10/255.0f, 1.0f);
 
271
    cr.stroke ();
 
272
 
 
273
    propagate_draw (_vbox, cr);
 
274
 
 
275
    cr.restore ();
 
276
 
 
277
    cr.pop_group_to_source ();
 
278
    cr.paint_with_alpha (_anim_offset);
 
279
    return true;
 
280
  }
 
281
}